chore: desktop workflow
This commit is contained in:
25
packages/desktop/scripts/runCommand.mjs
Normal file
25
packages/desktop/scripts/runCommand.mjs
Normal file
@@ -0,0 +1,25 @@
|
||||
import { spawn } from 'child_process'
|
||||
|
||||
export function runCommand(commandObj) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const { prompt, extraEnv } = commandObj
|
||||
|
||||
console.log(prompt, Object.keys(extraEnv).length > 0 ? extraEnv : '')
|
||||
|
||||
const [command, ...args] = prompt.split(' ')
|
||||
const options = { cwd: commandObj.dir, env: Object.assign({}, process.env, extraEnv) }
|
||||
const child = spawn(command, args, options)
|
||||
|
||||
child.stdout.pipe(process.stdout)
|
||||
child.stderr.pipe(process.stderr)
|
||||
|
||||
child.on('error', reject)
|
||||
child.on('close', (code) => {
|
||||
if (code > 0) {
|
||||
reject(code)
|
||||
} else {
|
||||
resolve(code)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user