Skip to content
This repository was archived by the owner on Oct 28, 2020. It is now read-only.

Commit 8590e4b

Browse files
committed
style(cli): added colors to promisified gulp commands
1 parent b318b48 commit 8590e4b

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

gulpfile.babel.js

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import mkdirp from 'mkdirp';
99
import path from 'path';
1010
import readPackage from 'read-package-json';
1111

12-
let exec = childProcess.exec;
1312
let pkg = Promise.promisify(readPackage);
1413
let readFile = Promise.promisify(fs.readFile);
14+
let spawn = childProcess.spawn;
1515
let writeFile = Promise.promisify(fs.writeFile);
1616

1717
const gp = gulpLoadPlugins();
@@ -25,29 +25,27 @@ const paths = {
2525
};
2626

2727
/**
28-
* Promisified child_process.exec
29-
* @param cmd
30-
* @param {Object} [opts={}] See child_process.exec node docs
31-
* @property {stream.Writable} [opts.stdout=process.stdout] - If defined, child process stdout will be piped to it.
32-
* @property {stream.Writable} [opts.stderr=process.stderr] - If defined, child process stderr will be piped to it.
33-
* @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>}
3435
*/
35-
function execp(cmd, opts = {}) {
36+
function spawnp(proc, args = [], opts = { stdio: `inherit` }) {
3637
return new Promise((resolve, reject) => {
37-
const child = exec(cmd, opts,
38-
(err, stdout, stderr) => {
39-
return err ? reject(err) : resolve({
40-
"stdout": stdout,
41-
"stderr": stderr
42-
});
43-
});
38+
const child = spawn(proc, args, opts);
39+
40+
child.on(`error`, (err) => {
41+
reject(err);
42+
});
4443

45-
if (opts.stdout) {
46-
child.stdout.pipe(opts.stdout);
47-
}
48-
if (opts.stderr) {
49-
child.stderr.pipe(opts.stderr);
50-
}
44+
child.on(`close`, (code) => {
45+
if (code === 0) {
46+
resolve();
47+
}
48+
});
5149
});
5250
}
5351

@@ -150,15 +148,15 @@ gulp.task(`nsp`, (cb) => {
150148
});
151149

152150
gulp.task(`snyk`, () => {
153-
return execp(`node_modules/.bin/snyk test`);
151+
return spawnp(`node_modules/.bin/snyk`, ["test", "--debug"]);
154152
});
155153

156154
gulp.task(`bithound`, () => {
157155
return pkg(paths.pkg, console.log, true).then((data) => {
158156
let pkgName = data.name;
159157
let pkgUser = data.repository.url.match(/github\.com\/([^\/]+)\//i)[1];
160158

161-
return execp(`node_modules/.bin/bithound check [email protected]:${pkgUser}/${pkgName}.git`);
159+
return spawnp(`node_modules/.bin/bithound`, [`check`, `[email protected]:${pkgUser}/${pkgName}.git`]);
162160
});
163161
});
164162

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"commitizen": "^2.8.2",
4747
"conventional-changelog": "^1.1.0",
4848
"cz-conventional-changelog": "^1.1.6",
49+
"del": "^2.2.1",
4950
"esdoc": "^0.4.7",
5051
"esdoc-hacker-vision": "^1.1.0",
5152
"esdoc-node": "^1.0.0",
@@ -67,8 +68,7 @@
6768
"nsp": "^2.6.1",
6869
"read-package-json": "^2.0.4",
6970
"semantic-release": "^6.3.0",
70-
"snyk": "^1.17.4",
71-
"del": "^2.2.1"
71+
"snyk": "^1.17.4"
7272
},
7373
"config": {
7474
"commitizen": {

0 commit comments

Comments
 (0)