UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

46 lines (44 loc) 1.2 kB
import { execa } from "execa"; //#region src/utils/run.ts async function run(cmd, args, options = {}) { const proc = execa(cmd, args, { cwd: options.cwd, env: options.env ? { ...process.env, ...options.env } : process.env, stdio: options.capture ? "pipe" : "inherit", reject: false }); let capturedStdout = ""; let capturedStderr = ""; if (options.capture && options.onChunk) { proc.stdout?.on("data", (chunk) => { capturedStdout += chunk.toString("utf-8"); options.onChunk("stdout", chunk); }); proc.stderr?.on("data", (chunk) => { capturedStderr += chunk.toString("utf-8"); options.onChunk("stderr", chunk); }); } await proc; if (!options.capture) { const exitCode = proc.exitCode ?? 0; if (exitCode !== 0) throw new Error(`${cmd} ${args.join(" ")} failed with exit code ${exitCode}`); return; } if (options.onChunk) return { stdout: capturedStdout, stderr: capturedStderr, exitCode: proc.exitCode ?? 0 }; return { stdout: typeof proc.stdout === "string" ? proc.stdout : "", stderr: typeof proc.stderr === "string" ? proc.stderr : "", exitCode: proc.exitCode ?? 0 }; } //#endregion export { run }; //# sourceMappingURL=run.mjs.map