mirror of
https://github.com/luckyyzh/pi-agent-integrated.git
synced 2026-10-03 02:59:35 +00:00
* feat: prepare self-contained open-source release * fix: canonicalize missing managed paths --------- Co-authored-by: luckyyzh <luckyyzh@users.noreply.github.com>
40 lines
1013 B
JavaScript
40 lines
1013 B
JavaScript
import { spawn } from "node:child_process";
|
|
import { join } from "node:path";
|
|
import { managedEnvironment, rootDir } from "./profile.mjs";
|
|
|
|
const target = process.argv[2] ?? "dev";
|
|
const allowedTargets = new Set(["build", "dev", "dev:lan", "start", "start:lan"]);
|
|
if (!allowedTargets.has(target)) {
|
|
console.error(`Unsupported Pi Web script: ${target}`);
|
|
process.exit(2);
|
|
}
|
|
|
|
const npmCliPath = process.env.npm_execpath;
|
|
if (!npmCliPath) {
|
|
console.error("Run the integrated application through npm.");
|
|
process.exit(1);
|
|
}
|
|
|
|
const child = spawn(
|
|
process.execPath,
|
|
[npmCliPath, "--prefix", join(rootDir, "pi-web"), "run", target],
|
|
{
|
|
cwd: rootDir,
|
|
env: managedEnvironment(),
|
|
stdio: "inherit",
|
|
},
|
|
);
|
|
|
|
for (const signal of ["SIGINT", "SIGTERM"]) {
|
|
process.on(signal, () => child.kill(signal));
|
|
}
|
|
|
|
child.on("error", (error) => {
|
|
console.error(error);
|
|
process.exit(1);
|
|
});
|
|
child.on("exit", (code, signal) => {
|
|
if (signal) process.kill(process.pid, signal);
|
|
process.exit(code ?? 1);
|
|
});
|