@@ -20,8 +20,15 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<strin
20
20
) ) ;
21
21
22
22
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 } ...` ) ) ;
25
32
console . log ( blue ( ` CWD: ${ cwd } ` ) ) ;
26
33
const spawnOptions : any = { cwd} ;
27
34
@@ -31,8 +38,8 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<strin
31
38
spawnOptions [ 'stdio' ] = 'pipe' ;
32
39
}
33
40
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 ) => {
36
43
stdout += data . toString ( 'utf-8' ) ;
37
44
if ( options . silent ) {
38
45
return ;
@@ -42,21 +49,21 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<strin
42
49
. filter ( line => line !== '' )
43
50
. forEach ( line => console . log ( ' ' + line ) ) ;
44
51
} ) ;
45
- npmProcess . stderr . on ( 'data' , ( data : Buffer ) => {
52
+ childProcess . stderr . on ( 'data' , ( data : Buffer ) => {
46
53
stderr += data . toString ( 'utf-8' ) ;
47
54
data . toString ( 'utf-8' )
48
55
. split ( / [ \n \r ] + / )
49
56
. filter ( line => line !== '' )
50
57
. forEach ( line => console . error ( yellow ( ' ' + line ) ) ) ;
51
58
} ) ;
52
59
53
- _processes . push ( npmProcess ) ;
60
+ _processes . push ( childProcess ) ;
54
61
55
62
// Create the error here so the stack shows who called this function.
56
63
const err = new Error ( `Running "${ cmd } ${ args . join ( ' ' ) } " returned error code ` ) ;
57
64
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 ) ;
60
67
61
68
if ( ! error ) {
62
69
resolve ( stdout ) ;
@@ -67,7 +74,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<strin
67
74
} ) ;
68
75
69
76
if ( options . waitForMatch ) {
70
- npmProcess . stdout . on ( 'data' , ( data : Buffer ) => {
77
+ childProcess . stdout . on ( 'data' , ( data : Buffer ) => {
71
78
if ( data . toString ( ) . match ( options . waitForMatch ) ) {
72
79
resolve ( stdout ) ;
73
80
}
@@ -113,6 +120,10 @@ export function npm(...args: string[]) {
113
120
return _exec ( { } , 'npm' , args ) ;
114
121
}
115
122
123
+ export function node ( ...args : string [ ] ) {
124
+ return _exec ( { } , 'node' , args ) ;
125
+ }
126
+
116
127
export function git ( ...args : string [ ] ) {
117
128
return _exec ( { } , 'git' , args ) ;
118
129
}
0 commit comments