in build/src/utils/async.js [25:71]
spawn: async (command, args, opts) => {
console.log(`(*) Spawn: ${command}${args.reduce((prev, current) => `${prev} ${current}`, '')}`);
opts = opts || { stdio: 'inherit', shell: true };
let echo = false;
if (opts.stdio === 'inherit') {
opts.stdio = 'pipe';
echo = true;
}
return new Promise((resolve, reject) => {
let result = '';
const proc = spawnCb(command, args, opts);
proc.on('close', (code, signal) => {
if (code !== 0) {
if(!echo) {
console.error(result);
}
const err = new Error(`Non-zero exit code: ${code} ${signal || ''}`);
err.result = result;
err.code = code;
err.signal = signal;
reject(err);
return;
}
resolve(result);
});
if (proc.stdout) {
proc.stdout.on('data', (chunk) => {
const stringChunk = chunk.toString();
result += stringChunk;
if (echo) {
process.stdout.write(stringChunk);
}
});
}
if (proc.stderr) {
proc.stderr.on('data', (chunk) => {
const stringChunk = chunk.toString();
result += stringChunk;
if (echo) {
process.stderr.write(stringChunk);
}
});
}
proc.on('error', reject);
});
},