Files
mqtt-explorer/scripts/util.ts
greenkeeper[bot] f8648b92a1 Update dependencies to enable Greenkeeper 🌴 (#121)
* chore: add Greenkeeper config file

* chore(package): update dependencies

* chore(package): update dependencies

* docs(readme): add Greenkeeper badge

* chore(package): update lockfile app/yarn.lock

* chore(package): update lockfile yarn.lock

* Fix update specific issues

* Fix AceEditor
2019-06-05 11:48:15 +02:00

30 lines
840 B
TypeScript

import { spawn, ChildProcess } from 'child_process'
export async function exec(cmd: string, args: string[] = []) {
const child = spawn(cmd, args, { shell: true })
redirectOutputFor(child)
await waitFor(child)
}
function redirectOutputFor(child: ChildProcess) {
const printStdout = (data: Buffer) => {
process.stdout.write(data.toString())
}
const printStderr = (data: Buffer) => {
process.stderr.write(data.toString())
}
child.stdout && child.stdout.on('data', printStdout)
child.stderr && child.stderr.on('data', printStderr)
child.once('close', () => {
child.stdout && child.stdout.off('data', printStdout)
child.stderr && child.stderr.off('data', printStderr)
})
}
async function waitFor(child: ChildProcess) {
return new Promise((resolve) => {
child.once('close', () => resolve())
})
}