1
0

refactor: 迁移 Bun fullstack 架构

This commit is contained in:
2026-05-14 00:23:37 +08:00
parent bcfac52112
commit 6e485cc991
36 changed files with 403 additions and 1081 deletions

View File

@@ -1,57 +0,0 @@
interface ChildProcessInfo {
name: string;
process: Bun.Subprocess;
}
const configPath = process.argv[2];
const env = {
...process.env,
BACKEND_PORT: process.env["PORT"] ?? "3000",
};
const children: ChildProcessInfo[] = [
{
name: "server",
process: Bun.spawn(["bun", "run", "dev:server", ...(configPath ? [configPath] : [])], {
env,
stderr: "inherit",
stdout: "inherit",
}),
},
{
name: "web",
process: Bun.spawn(["bun", "run", "dev:web"], {
env,
stderr: "inherit",
stdout: "inherit",
}),
},
];
const stopChildren = () => {
for (const child of children) {
child.process.kill();
}
};
process.on("SIGINT", () => {
stopChildren();
process.exit(130);
});
process.on("SIGTERM", () => {
stopChildren();
process.exit(143);
});
const firstExit = await Promise.race(
children.map(async (child) => ({ code: await child.process.exited, name: child.name })),
);
stopChildren();
if (firstExit.code !== 0) {
console.error(`${firstExit.name} exited with code ${firstExit.code}`);
process.exit(firstExit.code ?? 1);
}