Skip to content

Commit

Permalink
feat(): ensure child spawned processes for npm run print colors.
Browse files Browse the repository at this point in the history
  • Loading branch information
jthoms1 committed Oct 14, 2016
1 parent 157aefd commit f74e3c3
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,30 +316,27 @@ Cli.runWithNpmScripts = function runWithNpmScripts(argv, taskInstance, rawCliArg

Cli.runNpmHook = function runNpmHook(hook) {
var cmd = 'npm';
var args = ['run', hook];
var args = ['run', hook, '--color'];
var command = cmd + ' ' + args;

var q = Q.defer();
var spawn = require('cross-spawn-async');

var spawned = spawn('npm', args);
var spawned = spawn('npm', args, { stdio: ['pipe', 'pipe', process.stderr] });
spawned.on('error', function(err) {
log.error('Unable to run spawn command ' + err);
});
spawned.stdout.pipe(process.stdout);
spawned.stdout.on('data', function(data) {
var dataLines = data.toString().split('\n');
for (var i = 0; i < dataLines.length; i++) {
if (dataLines[i].length) {
log.info(dataLines[i]);
if (dataLines[i].indexOf('watch ready') > -1) {
return q.resolve();
}
}
}
});
spawned.stderr.on('data', function(data) {
log.info(data.toString());
});
spawned.on('exit', function(code) {
log.debug('Spawn command', command, 'completed');
if (code !== 0) {
Expand Down

0 comments on commit f74e3c3

Please sign in to comment.