2016-11-03 3 views
0

대규모 프로젝트의 경우 작은 프로젝트를 고유 한 빌드 프로세스로 자체 폴더로 분리하는 것이 좋습니다.상위 프로세스와 같이 생성 된 꿀풀 프로세스의 출력 형식

다음 설정은 기본적으로 Windows와 Mac에서 모두 작동합니다. 콘솔에서만 발생하는 자식 꿀꺽 프로세스의 결과는 부모 프로세스의 출력과 같지 않습니다.

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); 
}); 

내 질문은 일반 꿀꺽 과정과 정확히 같은 방식으로 자식 꿀꺽 프로세스의 출력을 표시하는 방법입니다.

편집 : Is it possible for child processes in Node.js to preserve colored output?

답변

2

의 중복 당신은 부모 프로세스의 표준 입출력을 상속합니다. 이렇게하면 출력이 동일한 출력으로 색상 및 전체로 올바르게 파이프됩니다.

gulp을 사용하고 있기 때문에 꿀꺽 꿀꺽 소리가 제대로 감지되도록하려면 --color always 플래그를 추가해야합니다.

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'}); 
}); 
+1

Windows와 Mac에서 완벽하게 작동했습니다. 감사! –

관련 문제