1
+ import { SpawnOptions } from "child_process" ;
1
2
import * as child_process from 'child_process' ;
2
3
import { terminal } from '@angular-devkit/core' ;
3
4
import { Observable , concat , defer , EMPTY , from } from 'rxjs' ;
@@ -11,6 +12,7 @@ const treeKill = require('tree-kill');
11
12
interface ExecOptions {
12
13
silent ?: boolean ;
13
14
waitForMatch ?: RegExp ;
15
+ env ?: { [ varname : string ] : string } ;
14
16
}
15
17
16
18
@@ -26,6 +28,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proc
26
28
let stdout = '' ;
27
29
let stderr = '' ;
28
30
const cwd = process . cwd ( ) ;
31
+ const env = options . env ;
29
32
console . log (
30
33
`==========================================================================================`
31
34
) ;
@@ -41,7 +44,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proc
41
44
42
45
console . log ( terminal . blue ( `Running \`${ cmd } ${ args . map ( x => `"${ x } "` ) . join ( ' ' ) } \`${ flags } ...` ) ) ;
43
46
console . log ( terminal . blue ( `CWD: ${ cwd } ` ) ) ;
44
- const spawnOptions : any = { cwd} ;
47
+ const spawnOptions : SpawnOptions = { cwd, env } ;
45
48
46
49
if ( process . platform . startsWith ( 'win' ) ) {
47
50
args . unshift ( '/c' , cmd ) ;
@@ -146,6 +149,10 @@ export function silentExec(cmd: string, ...args: string[]) {
146
149
return _exec ( { silent : true } , cmd , args ) ;
147
150
}
148
151
152
+ export function execWithEnv ( cmd : string , args : string [ ] , env : { [ varname : string ] : string } ) {
153
+ return _exec ( { env } , cmd , args ) ;
154
+ }
155
+
149
156
export function execAndWaitForOutputToMatch ( cmd : string , args : string [ ] , match : RegExp ) {
150
157
if ( cmd === 'ng' && args [ 0 ] === 'serve' ) {
151
158
// Accept matches up to 20 times after the initial match.
0 commit comments