2026-07-28 02:12:46 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 并行启动:FastAPI(8000) + Vite(5173) —— Web 开发
|
|
|
|
|
|
* 无论从仓库根还是 apps/* 调用,都以本脚本所在仓库为 cwd。
|
|
|
|
|
|
*/
|
2026-08-26 00:25:46 +08:00
|
|
|
|
import { spawn, spawnSync } from 'node:child_process';
|
2026-07-28 02:12:46 +08:00
|
|
|
|
import path from 'node:path';
|
|
|
|
|
|
import process from 'node:process';
|
|
|
|
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
|
|
|
|
|
|
|
|
const isWin = process.platform === 'win32';
|
|
|
|
|
|
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
|
|
|
|
const kids = [];
|
|
|
|
|
|
|
|
|
|
|
|
function run(label, command, args, env = {}) {
|
|
|
|
|
|
const child = spawn(command, args, {
|
|
|
|
|
|
cwd: repoRoot,
|
|
|
|
|
|
env: {
|
|
|
|
|
|
...process.env,
|
|
|
|
|
|
APS_MODE: 'web',
|
2026-07-29 23:22:40 +08:00
|
|
|
|
APS_AUTH_PROVIDER: process.env.APS_AUTH_PROVIDER || 'jms',
|
2026-07-28 02:12:46 +08:00
|
|
|
|
...env,
|
|
|
|
|
|
},
|
|
|
|
|
|
stdio: 'inherit',
|
|
|
|
|
|
shell: isWin,
|
|
|
|
|
|
});
|
|
|
|
|
|
child.on('exit', (code) => {
|
|
|
|
|
|
console.log(`[${label}] exit ${code}`);
|
|
|
|
|
|
shutdown(code ?? 1);
|
|
|
|
|
|
});
|
|
|
|
|
|
kids.push(child);
|
|
|
|
|
|
return child;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function shutdown(code = 0) {
|
|
|
|
|
|
for (const c of kids) {
|
2026-08-26 00:25:46 +08:00
|
|
|
|
if (!Number.isInteger(c.pid) || c.pid <= 0) continue;
|
|
|
|
|
|
if (isWin) {
|
|
|
|
|
|
spawnSync('taskkill.exe', ['/pid', String(c.pid), '/T', '/F'], {
|
|
|
|
|
|
stdio: 'ignore',
|
|
|
|
|
|
windowsHide: true,
|
|
|
|
|
|
});
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2026-07-28 02:12:46 +08:00
|
|
|
|
try { c.kill(); } catch { /* ignore */ }
|
|
|
|
|
|
}
|
|
|
|
|
|
process.exit(code);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
process.on('SIGINT', () => shutdown(0));
|
|
|
|
|
|
process.on('SIGTERM', () => shutdown(0));
|
|
|
|
|
|
|
|
|
|
|
|
const py = process.env.PYTHON || (isWin ? 'python' : 'python3');
|
|
|
|
|
|
run('api', py, ['-m', 'uvicorn', 'server.main:app', '--reload', '--port', '8000']);
|
|
|
|
|
|
run('web', isWin ? 'npm.cmd' : 'npm', ['run', 'dev', '--prefix', 'apps/web']);
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`\nAPS Web 开发(cwd=${repoRoot}):API :8000 UI :5173\n`);
|