import { exec } from 'child_process' ; export class CommandOutput { stdout = '' ; stderr = '' ; exitCode : number = - 1 ; } export let ENVIRONMENT = process . env ; export function execute ( command , exitOnError = true ) { console . log ( '> ' + command ) ; return new Promise < CommandOutput > ( ( resolve , reject ) => { const child = exec ( command , { env : ENVIRONMENT } ) ; let output = new CommandOutput ( ) ; child . stdout ?. on ( 'data' , ( data ) => { console . log ( data . toString ( ) ) ; output . stdout = output . stdout + data . toString ( ) ; } ) ; child . stderr ?. on ( 'data' , ( data ) => { console . error ( data . toString ( ) ) ; output . stderr = output . stderr + data . toString ( ) ; } ) ; child . on ( 'exit' , ( code ) => { output . exitCode = code ; if ( code == 0 ) { resolve ( output ) ; } else { if ( exitOnError ) process . exit ( 1 ) ; else resolve ( output ) ; } } ) ; } ) ; }