import { resolve as resolvePath } from 'path' ; import { spawn } from 'child_process' ; import { red } from 'chalk' ; param binary param flags returns export function tsCompile ( binary , flags ) { return new Promise ( ( resolve , reject ) => { const binaryPath = resolvePath ( `./node_modules/.bin/${ binary }` ) ; const childProcess = spawn ( binaryPath , flags , { shell : true } ) ; childProcess . stdout . on ( 'data' , ( data ) => console . log ( `${ data }` ) ) ; childProcess . stderr . on ( 'data' , ( data ) => console . error ( red ( `${ data }` ) ) ) ; childProcess . on ( 'exit' , ( exitCode ) => { exitCode === 0 ? resolve ( ) : reject ( `${ binary } compilation failure` ) ; } ) ; } ) ; }