spiegel-keyman/resources/build/version/src/util/spawnAwait.ts
Marc Durdin eff292c6b3 chore(ci): increment version final
This prepares a PR with updated history and version
for auto-merge. Any new PRs are merged into HISTORY.md
but existing entries are left untouched. Thus, we can
tweak wording in HISTORY.md at any time without the
effort of figuring out which PRs need to be present
manually.
2020-02-03 09:33:46 +11:00

27 lines
658 B
TypeScript

import { spawn } from 'child_process';
export const spawnChild = async function(cmd: string, params: string[]) {
const child = spawn(cmd, params);
let data = "";
for await (const chunk of child.stdout) {
//console.log('stdout chunk: '+chunk);
data += chunk;
}
let error = "";
for await (const chunk of child.stderr) {
//console.error('stderr chunk: '+chunk);
error += chunk;
}
const exitCode = await new Promise( (resolve) => {
child.on('close', resolve);
});
if(exitCode) {
throw new Error(`subprocess error exit ${exitCode}, ${error}`);
}
return data;
}