import { execSync , spawn } from 'child_process' ; export async function sleep ( ms ) { return new Promise ( resolve => setTimeout ( resolve , ms ) ) ; } export function execCommand ( command ) { return String ( execSync ( command ) ) . trim ( ) ; } export function execCommandSafe ( command ) { try { return execCommand ( command ) ; } catch ( e ) { return String ( e ) ; } } export function spawnProcess ( command , args , onClose ? ) { const childProcess = spawn ( command , args , { shell : true } ) ; childProcess . stdout . on ( 'data' , out => { process . stdout . write ( out ) ; } ) ; childProcess . stderr . on ( 'data' , stderr => { process . stderr . write ( stderr ) ; } ) ; childProcess . on ( 'close' , code => { onClose && onClose ( ) ; process . stdout . write ( `child process exited with code ${ String ( code ) }` ) ; } ) ; } export function spawnNpmScript ( script , onClose ? ) { spawnProcess ( 'npm' , [ 'run' , script ] , onClose ) ; }