Spaces:
Sleeping
Sleeping
File size: 1,623 Bytes
5743bc2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | import { spawn } from "node:child_process";
import path from "node:path";
const rootDir = path.resolve(import.meta.dirname, "..");
const isWindows = process.platform === "win32";
const pnpmExec =
process.env.npm_execpath && process.env.npm_execpath.toLowerCase().includes("pnpm")
? process.env.npm_execpath
: null;
const nodeBin = process.execPath;
function run(command, args, options = {}) {
return new Promise((resolve, reject) => {
const child = spawn(command, args, {
cwd: rootDir,
stdio: "inherit",
shell: false,
...options,
});
child.on("error", reject);
child.on("exit", (code, signal) => {
if (signal) {
reject(new Error(`Process terminated by signal ${signal}`));
return;
}
if (code !== 0) {
reject(new Error(`Process exited with code ${code}`));
return;
}
resolve();
});
});
}
if (pnpmExec) {
await run(nodeBin, [pnpmExec, "--filter", "@workspace/api-server", "run", "build"]);
} else {
await run(isWindows ? "pnpm.cmd" : "pnpm", ["--filter", "@workspace/api-server", "run", "build"]);
}
const server = spawn(
nodeBin,
[path.join("artifacts", "api-server", "dist", "index.mjs")],
{
cwd: rootDir,
stdio: "inherit",
env: {
...process.env,
NODE_ENV: process.env.NODE_ENV ?? "development",
PORT: process.env.API_PORT ?? process.env.PORT ?? "3001",
},
shell: false,
},
);
server.on("exit", (code) => {
process.exit(code ?? 0);
});
for (const signal of ["SIGINT", "SIGTERM"]) {
process.on(signal, () => {
server.kill(signal);
});
}
|