refactor(release): extract dotenv/snapshot/workflow shared lib

This commit is contained in:
ZacharyZhang-NY committed 2026-04-16 22:26:11 -04:00
1 parent 466dac117d
commit d2078446b4
4 files changed
+257

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
import { spawn } from "node:child_process";
export function createRunner(rootDir) {
return function run(command, args, options = {}) {
const {
cwd = rootDir,
env = process.env,
input = null,
capture = false,
} = options;
return new Promise((resolve, reject) => {
const child = spawn(command, args, {
cwd,
env,
stdio: capture ? ["pipe", "pipe", "pipe"] : ["pipe", "inherit", "inherit"],
shell: process.platform === "win32",
});
let stdout = "";
let stderr = "";
if (capture) {
child.stdout.on("data", (chunk) => {
stdout += chunk.toString();
});
child.stderr.on("data", (chunk) => {
stderr += chunk.toString();
});
}
if (input) {
child.stdin.write(input);
}
child.stdin.end();
child.on("error", reject);
child.on("close", (code) => {
if (code === 0) {
resolve({ stdout, stderr });
return;
}
reject(new Error(stderr || stdout || `${command} ${args.join(" ")} failed with exit code ${code ?? 1}`));
});
});
};
}