import type {Bud} from '@roots/bud-framework' import type {ExecaChildProcess, Options} from '@roots/bud-support/execa' import execa from '@roots/bud-support/execa' export interface sh { (command: Array | string, options?: Options): ExecaChildProcess } /** * Execute a shell command * * @example * ```js * bud.sh(`ls -la`) * ``` */ export const sh: sh = function ( command: Array | string, options = {}, ) { const bud = this as Bud const commandInput = (Array.isArray(command) ? command : [command]) .map(str => str.split(` `)) .flat() const bin = commandInput.shift() if (!bin) { throw new Error(`No command provided`) } const child = execa(bin, commandInput.filter(Boolean), { cwd: bud.context.basedir, ...options, }) child.stdout?.pipe(process.stdout) child.stderr?.pipe(process.stderr) return child }