@@ -20,8 +20,15 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<strin
2020 ) ) ;
2121
2222 args = args . filter ( x => x !== undefined ) ;
23-
24- console . log ( blue ( ` Running \`${ cmd } ${ args . map ( x => `"${ x } "` ) . join ( ' ' ) } \`...` ) ) ;
23+ const flags = [
24+ options . silent && 'silent' ,
25+ options . waitForMatch && `matching(${ options . waitForMatch } )`
26+ ]
27+ . filter ( x => ! ! x ) // Remove false and undefined.
28+ . join ( ', ' )
29+ . replace ( / ^ ( .+ ) $ / , ' [$1]' ) ; // Proper formatting.
30+
31+ console . log ( blue ( ` Running \`${ cmd } ${ args . map ( x => `"${ x } "` ) . join ( ' ' ) } \`${ flags } ...` ) ) ;
2532 console . log ( blue ( ` CWD: ${ cwd } ` ) ) ;
2633 const spawnOptions : any = { cwd} ;
2734
@@ -31,8 +38,8 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<strin
3138 spawnOptions [ 'stdio' ] = 'pipe' ;
3239 }
3340
34- const npmProcess = child_process . spawn ( cmd , args , spawnOptions ) ;
35- npmProcess . stdout . on ( 'data' , ( data : Buffer ) => {
41+ const childProcess = child_process . spawn ( cmd , args , spawnOptions ) ;
42+ childProcess . stdout . on ( 'data' , ( data : Buffer ) => {
3643 stdout += data . toString ( 'utf-8' ) ;
3744 if ( options . silent ) {
3845 return ;
@@ -42,21 +49,21 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<strin
4249 . filter ( line => line !== '' )
4350 . forEach ( line => console . log ( ' ' + line ) ) ;
4451 } ) ;
45- npmProcess . stderr . on ( 'data' , ( data : Buffer ) => {
52+ childProcess . stderr . on ( 'data' , ( data : Buffer ) => {
4653 stderr += data . toString ( 'utf-8' ) ;
4754 data . toString ( 'utf-8' )
4855 . split ( / [ \n \r ] + / )
4956 . filter ( line => line !== '' )
5057 . forEach ( line => console . error ( yellow ( ' ' + line ) ) ) ;
5158 } ) ;
5259
53- _processes . push ( npmProcess ) ;
60+ _processes . push ( childProcess ) ;
5461
5562 // Create the error here so the stack shows who called this function.
5663 const err = new Error ( `Running "${ cmd } ${ args . join ( ' ' ) } " returned error code ` ) ;
5764 return new Promise ( ( resolve , reject ) => {
58- npmProcess . on ( 'exit' , ( error : any ) => {
59- _processes = _processes . filter ( p => p !== npmProcess ) ;
65+ childProcess . on ( 'exit' , ( error : any ) => {
66+ _processes = _processes . filter ( p => p !== childProcess ) ;
6067
6168 if ( ! error ) {
6269 resolve ( stdout ) ;
@@ -67,7 +74,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<strin
6774 } ) ;
6875
6976 if ( options . waitForMatch ) {
70- npmProcess . stdout . on ( 'data' , ( data : Buffer ) => {
77+ childProcess . stdout . on ( 'data' , ( data : Buffer ) => {
7178 if ( data . toString ( ) . match ( options . waitForMatch ) ) {
7279 resolve ( stdout ) ;
7380 }
@@ -113,6 +120,10 @@ export function npm(...args: string[]) {
113120 return _exec ( { } , 'npm' , args ) ;
114121}
115122
123+ export function node ( ...args : string [ ] ) {
124+ return _exec ( { } , 'node' , args ) ;
125+ }
126+
116127export function git ( ...args : string [ ] ) {
117128 return _exec ( { } , 'git' , args ) ;
118129}
0 commit comments