(cmd: string, opts: RunOpts = {})
| 9 | |
| 10 | type RunOpts = { cwd?: string; inherit?: boolean }; |
| 11 | function run(cmd: string, opts: RunOpts = {}) { |
| 12 | const exOpts: ExecSyncOptions = { |
| 13 | cwd: opts.cwd, |
| 14 | stdio: opts.inherit ? "inherit" : "pipe", |
| 15 | encoding: "utf8", |
| 16 | }; |
| 17 | try { |
| 18 | const res = execSync(cmd, exOpts); |
| 19 | if (opts.inherit) return ""; |
| 20 | if (typeof res === "string") return res.trim(); |
| 21 | return (res?.toString?.("utf8") ?? "").trim(); |
| 22 | } catch (err: unknown) { |
| 23 | const msg = err instanceof Error ? err.message : String(err); |
| 24 | throw new Error(`Command failed: ${cmd}\n${msg}`); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | const ensureDir = (p: string) => mkdirSync(p, { recursive: true }); |
| 29 | const resetDir = (p: string) => { if (existsSync(p)) rmSync(p, { recursive: true, force: true }); ensureDir(p); }; |
no outgoing calls
no test coverage detected