Repository URL to install this package:
|
Version:
3.0.0-beta.2 ▾
|
export interface Output {
stdout?: string | Buffer
stderr?: string | Buffer
}
export type ErrorWithOutput = Error &
Output & {
code?: number
signal?: string
}
export interface SpawnScriptArgs {
[key: string]: [string, ReadonlyArray<string>]
}
export type ExceptionFromChildProcess = Error & { stdout?: string } | string
export interface AnyObj {
[key: string]: any
}
import { promisify } from 'util'
import { spawn as nodeSpawn, SpawnOptions } from 'child_process'
export const spawn = promisify(nodeSpawn)
export const colorSpawn = (command: string, args: any) => {
const options: SpawnOptions = {
stdio: 'inherit',
env: process.env,
}
return spawn(command, args, options)
}
export const fromExceptionToStdout = (exception: ExceptionFromChildProcess) => {
if (typeof exception === 'object' && exception.stdout) {
return exception.stdout.toString()
} else {
return exception
}
}
export function fromResultToStdout(result: Output) {
if (result.stdout && result.stderr) {
return result.stdout.toString() + '\n' + result.stderr.toString()
} else if (result.stdout) {
return result.stdout.toString()
} else if (result.stderr) {
return result.stderr.toString()
} else {
return 'no output!!!'
}
}