Files
gui/scripts/spawnify.ts
T
natew eda78d2b38 fix(release): allow npm passkey authentication
Agentbus-Session: ab-mrr29x1f-51747
2026-07-18 15:24:47 -10:00

51 lines
1.3 KiB
TypeScript

import * as proc from 'node:child_process'
export const spawn = proc.spawn
// could add only if changed checks: git diff --quiet HEAD HEAD~3 -- ./packages/core
// but at that point would be nicer to get a whole setup for this.. lerna or whatever
export const spawnify = async (
cmd: string,
opts?: proc.SpawnOptionsWithoutStdio & {
avoidLog?: boolean
interactive?: boolean
cwd?: string
}
): Promise<string> => {
console.info('>', cmd)
const [head, ...rest] = cmd.split(' ')
return new Promise((res, rej) => {
const { avoidLog, interactive, cwd, ...spawnOpts } = opts || {}
const child = spawn(head, rest, {
stdio: interactive ? 'inherit' : avoidLog ? undefined : ['inherit', 'pipe', 'pipe'],
cwd,
shell: true,
...spawnOpts,
})
const outStr = []
const errStr = []
if (!avoidLog && !interactive) {
child.stdout?.pipe(process.stdout)
child.stderr?.pipe(process.stderr)
}
child.stdout?.on('data', (out) => {
// @ts-ignore
outStr.push(`${out}`)
})
child.stderr?.on('data', (out) => {
// @ts-ignore
errStr.push(`${out}`)
})
child.on('error', (err) => {
rej(err)
})
child.on('close', (code) => {
if (code === 0) {
res(outStr.join('\n'))
} else {
rej(errStr.join('\n'))
}
})
})
}