1- import BluebirdPromise from "bluebird-lst"
1+ import { path7za } from "7zip-bin"
2+ import { appBuilderPath } from "app-builder-bin"
23import { safeStringifyJson } from "builder-util-runtime"
34import chalk from "chalk"
45import { ChildProcess , execFile , ExecFileOptions , spawn as _spawn , SpawnOptions } from "child_process"
@@ -83,7 +84,7 @@ export function exec(file: string, args?: Array<string> | null, options?: ExecFi
8384 log . debug ( logFields , "executing" )
8485 }
8586
86- return new BluebirdPromise < string > ( ( resolve , reject ) => {
87+ return new Promise < string > ( ( resolve , reject ) => {
8788 execFile ( file , args , {
8889 ...options ,
8990 maxBuffer : 10 * 1024 * 1024 ,
@@ -139,6 +140,22 @@ export interface ExtraSpawnOptions {
139140 isPipeInput ?: boolean
140141}
141142
143+ function logSpawn ( command : string , args : Array < string > , options : SpawnOptions ) {
144+ // use general debug.enabled to log spawn, because it doesn't produce a lot of output (the only line), but important in any case
145+ if ( ! log . isDebugEnabled ) {
146+ return
147+ }
148+
149+ const argsString = args . join ( " " )
150+ const logFields : any = {
151+ command : command + " " + ( command === "docker" ? argsString : removePassword ( argsString ) ) ,
152+ }
153+ if ( options != null && options . cwd != null ) {
154+ logFields . cwd = options . cwd
155+ }
156+ log . debug ( logFields , "spawning" )
157+ }
158+
142159export function doSpawn ( command : string , args : Array < string > , options ?: SpawnOptions , extraOptions ?: ExtraSpawnOptions ) : ChildProcess {
143160 if ( options == null ) {
144161 options = { }
@@ -152,19 +169,7 @@ export function doSpawn(command: string, args: Array<string>, options?: SpawnOpt
152169 options . stdio = [ extraOptions != null && extraOptions . isPipeInput ? "pipe" : "ignore" , isDebugEnabled ? "inherit" : "pipe" , isDebugEnabled ? "inherit" : "pipe" ]
153170 }
154171
155- // use general debug.enabled to log spawn, because it doesn't produce a lot of output (the only line), but important in any case
156- if ( log . isDebugEnabled ) {
157- const argsString = args . join ( " " )
158- const logFields : any = {
159- command,
160- args : command === "docker" ? argsString : removePassword ( argsString ) ,
161- }
162- if ( options != null && options . cwd != null ) {
163- logFields . cwd = options . cwd
164- }
165- log . debug ( logFields , "spawning" )
166- }
167-
172+ logSpawn ( command , args , options )
168173 try {
169174 return _spawn ( command , args , options )
170175 }
@@ -176,7 +181,7 @@ export function doSpawn(command: string, args: Array<string>, options?: SpawnOpt
176181export function spawnAndWrite ( command : string , args : Array < string > , data : string , options ?: SpawnOptions , isDebugEnabled : boolean = false ) {
177182 const childProcess = doSpawn ( command , args , options , { isPipeInput : true , isDebugEnabled} )
178183 const timeout = setTimeout ( ( ) => childProcess . kill ( ) , 4 * 60 * 1000 )
179- return new BluebirdPromise < any > ( ( resolve , reject ) => {
184+ return new Promise < any > ( ( resolve , reject ) => {
180185 handleProcess ( "close" , childProcess , command , false , ( ) => {
181186 try {
182187 clearTimeout ( timeout )
@@ -198,7 +203,7 @@ export function spawnAndWrite(command: string, args: Array<string>, data: string
198203}
199204
200205export function spawn ( command : string , args ?: Array < string > | null , options ?: SpawnOptions , extraOptions ?: ExtraSpawnOptions ) : Promise < any > {
201- return new BluebirdPromise < any > ( ( resolve , reject ) => {
206+ return new Promise < any > ( ( resolve , reject ) => {
202207 const isCollectOutput = options != null && ( options . stdio === "pipe" || ( Array . isArray ( options . stdio ) && options . stdio . length === 3 && options . stdio [ 1 ] === "pipe" ) )
203208 handleProcess ( "close" , doSpawn ( command , args || [ ] , options , extraOptions ) , command , isCollectOutput , resolve , reject )
204209 } )
@@ -344,4 +349,17 @@ export class InvalidConfigurationError extends Error {
344349
345350 ( this as any ) . code = code
346351 }
347- }
352+ }
353+
354+ export function executeAppBuilder ( args : Array < string > ) : Promise < string > {
355+ return new Promise < string > ( ( resolve , reject ) => {
356+ const command = appBuilderPath
357+ handleProcess ( "close" , doSpawn ( command , args , {
358+ env : {
359+ ...process . env ,
360+ SZA_PATH : path7za ,
361+ } ,
362+ stdio : [ "ignore" , "pipe" , "inherit" ]
363+ } ) , command , true , resolve , reject )
364+ } )
365+ }
0 commit comments