license import { ExecOptions } from 'child_process' ; import util = require ( 'util' ) ; const { promisify } = util ; const { execFile : _execFile } = require ( 'child_process' ) ; const execFile = promisify ( _execFile ) ; export interface ExecResult { stdout : string ; stderr : string ; } /**
 * A helper function for working with Node's core execFile() method.
 */ export default async function exec ( cwd , command , args ? , options ? ) { const commandOptions = { ... options , cwd : cwd } as ExecOptions ; try { const { stdout , stderr } = await execFile ( command , args , commandOptions ) ; return { stdout : stdout . trim ( ) , stderr : stderr . trim ( ) } ; } catch ( err ) { err . cwd = cwd ; throw err ; } } /**
 * A helper function to check whether a shell command exists or not.
 * Useful for user-facing warnings.
 */ export async function checkCommand ( commandName ) { try { await execFile ( 'command' , [ '-v' , commandName ] ) ; return true ; } catch ( err ) { return false ; } }