11import Promise from 'bluebird' ;
22import childProcess from 'child_process' ;
33import conventionalChangelog from 'conventional-changelog' ;
4+ import del from 'del' ;
45import fs from 'fs' ;
56import gulp from 'gulp' ;
67import gulpLoadPlugins from 'gulp-load-plugins' ;
8+ import mkdirp from 'mkdirp' ;
79import path from 'path' ;
810import readPackage from 'read-package-json' ;
911
10- let exec = childProcess . exec ;
1112let pkg = Promise . promisify ( readPackage ) ;
1213let readFile = Promise . promisify ( fs . readFile ) ;
14+ let spawn = childProcess . spawn ;
1315let writeFile = Promise . promisify ( fs . writeFile ) ;
1416
1517const gp = gulpLoadPlugins ( ) ;
@@ -23,29 +25,27 @@ const paths = {
2325} ;
2426
2527/**
26- * Promisified child_process.exec
27- * @param cmd
28- * @param {Object } [opts={}] See child_process.exec node docs
29- * @property {stream.Writable } [opts.stdout=process.stdout] - If defined, child process stdout will be piped to it.
30- * @property {stream.Writable } [opts.stderr=process.stderr] - If defined, child process stderr will be piped to it.
31- * @returns {Promise<{ stdout: string, stderr: stderr }> }
28+ * Promisified child_process.spawn
29+ * @async
30+ * @param {String } proc - The process we want to spawn
31+ * @param {Array } args - The arguments we want to spawn the process with
32+ * @param {Object } opts - See child_process.exec node docs
33+ * @param {String } [opts.stdio=`inherit`] - spawn environment inherits parent
34+ * @return {Promise<Error> }
3235 */
33- function execp ( cmd , opts = { } ) {
36+ function spawnp ( proc , args = [ ] , opts = { "stdio" : `inherit` } ) {
3437 return new Promise ( ( resolve , reject ) => {
35- const child = exec ( cmd , opts ,
36- ( err , stdout , stderr ) => {
37- return err ? reject ( err ) : resolve ( {
38- "stdout" : stdout ,
39- "stderr" : stderr
40- } ) ;
41- } ) ;
38+ const child = spawn ( proc , args , opts ) ;
39+
40+ child . on ( `error` , ( err ) => {
41+ reject ( err ) ;
42+ } ) ;
4243
43- if ( opts . stdout ) {
44- child . stdout . pipe ( opts . stdout ) ;
45- }
46- if ( opts . stderr ) {
47- child . stderr . pipe ( opts . stderr ) ;
48- }
44+ child . on ( `close` , ( code ) => {
45+ if ( code === 0 ) {
46+ resolve ( ) ;
47+ }
48+ } ) ;
4949 } ) ;
5050}
5151
@@ -148,15 +148,15 @@ gulp.task(`nsp`, (cb) => {
148148} ) ;
149149
150150gulp . task ( `snyk` , ( ) => {
151- return execp ( `node_modules/.bin/snyk test` ) ;
151+ return spawnp ( `node_modules/.bin/snyk` , [ " test" , "--debug" ] ) ;
152152} ) ;
153153
154154gulp . task ( `bithound` , ( ) => {
155155 return pkg ( paths . pkg , console . log , true ) . then ( ( data ) => {
156156 let pkgName = data . name ;
157157 let pkgUser = data . repository . url . match ( / g i t h u b \. c o m \/ ( [ ^ \/ ] + ) \/ / i) [ 1 ] ;
158158
159- return execp ( `node_modules/.bin/bithound check git@github.com:${ pkgUser } /${ pkgName } .git` ) ;
159+ return spawnp ( `node_modules/.bin/bithound` , [ ` check` , ` git@github.com:${ pkgUser } /${ pkgName } .git`] ) ;
160160 } ) ;
161161} ) ;
162162
@@ -168,8 +168,29 @@ gulp.task(`package`, () => {
168168 } ) ;
169169} ) ;
170170
171+ gulp . task ( `clean:docs` , ( ) => {
172+ return del ( [ `${ paths . docs } /*` ] ) ;
173+ } ) ;
174+
175+ gulp . task ( `clean:manual` , ( ) => {
176+ return del ( [ `${ paths . manual } /*` ] ) ;
177+ } ) ;
178+
179+ gulp . task ( `setup` , [ `clean` ] , ( ) => {
180+ let log = [
181+ mkdirp ( paths . docs ) ,
182+ mkdirp ( paths . manual )
183+ ] ;
184+
185+ return Promise . all ( log ) . then ( ( response ) => {
186+ return response ;
187+ } ) ;
188+ } ) ;
189+
190+ gulp . task ( `clean` , [ `clean:docs` , `clean:manual` ] ) ;
171191gulp . task ( `test:install` , [ `nsp` , `snyk` , `bithound` ] ) ;
172192gulp . task ( `test:publish` , [ `test:install` , `package` ] ) ;
173193gulp . task ( `prepublish` , [ `test:publish` ] ) ;
194+ gulp . task ( `pretest` , [ `setup` ] ) ;
174195gulp . task ( `test` , [ `test:install` , `lint` ] ) ;
175196gulp . task ( `default` , [ `test` ] ) ;
0 commit comments