Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/forms / danger / shell.ts
Size: Mime:
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!!!'
  }
}