像父进程一样格式化生成的 gulp 进程的输出

Format output of spawned gulp process like the parent process

用例:在大型项目中,将小型项目分成具有自己的构建过程的文件夹可能会很好。

以下设置基本上适用于 windows 和 mac - 我在控制台中记录了子 gulp 进程的输出 - 唯一的问题是它的颜色不像父进程的输出。

var spawnCmd = require('spawn-cmd');

gulp.task('default', function () {
    // Run all the parent projects tasks first
    // ....
    // ....
    // ....

    // When done, cd to child directory
    process.chdir('./some-dir-that-has-a-gulpfile');

    // Run `gulp` in the child directory
    var child = spawnCmd.spawn('gulp', ['default']);

    // And pipe the output to the current process
    child.stdout.pipe(process.stdout);
});

我的问题是如何以与正常 gulp 进程完全相同的方式显示子 gulp 进程的输出。

编辑:

的副本

你应该继承父进程的stdio。这正确地将输出通过管道传输到相同的输出,包括颜色和所有。

因为您正在使用 gulp,您还应该添加 --color always 标志,以便 gulp 正确检测到您想要的颜色。

var spawnCmd = require('spawn-cmd');

gulp.task('default', function () {
    // When done, cd to child directory
    process.chdir('./some-dir-that-has-a-gulpfile');

    // Run `gulp` in the child directory
    var child = spawnCmd.spawn('gulp', ['default', '--color', 'always'], {stdio: 'inherit'});
});