import child_process = require ( "child_process" ) ; import * as fs from "fs-extra" ; export default class SpawnCommand { public execCommand ( command , workingdirectory , args , fileToLog ) { return new Promise ( ( resolve , reject ) => { try { let childProcess ; childProcess = child_process . spawn ( command , args , { cwd : workingdirectory , } ) ; childProcess . stdout . on ( 'data' , ( data ) => { fs . appendFileSync ( fileToLog , data ) ; } ) ; childProcess . stderr . on ( 'data' , ( data ) => { fs . appendFileSync ( fileToLog , data ) ; } ) ; childProcess . once ( 'close' , ( code , signal ) => { if ( code === 0 || ( code === null && signal === "SIGTERM" ) ) { resolve ( fileToLog ) ; } else { reject ( fileToLog ) ; } } ) ; childProcess . once ( 'error' , ( err ) => { reject ( fileToLog ) ; } ) ; } catch ( error ) { reject ( error ) ; } } ) ; } }