import * as childProcess from 'child_process'; export const spawn = ( cwd: string, command: string, args: string[], parentProcess = process, ) => new Promise((resolve, reject) => { let stdout = ''; let stderr = ''; const theChildProcess = childProcess.spawn(command, args, { cwd, }); theChildProcess.stdout.on('data', (data) => { parentProcess.stdout.write(data); stdout += data; }); theChildProcess.stderr.on('data', (data) => { parentProcess.stderr.write(data); stderr += data; }); theChildProcess.on('close', (code) => { if (code !== 0) { reject(new Error(stderr)); return; } resolve(stdout); }) })