7a5b9cc912
Node < 24 lacks crypto.argon2Sync; wire @node-rs/argon2 fallback and start Admin API alongside vite preview in local and remote deploy flows. Co-authored-by: Cursor <cursoragent@cursor.com>
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
#!/usr/bin/env node
|
|
import { spawn } from 'node:child_process';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
const args = process.argv.slice(2);
|
|
|
|
function spawnChild(command, args, label) {
|
|
const child = spawn(command, args, {
|
|
cwd: root,
|
|
stdio: 'inherit',
|
|
env: process.env,
|
|
});
|
|
child.on('exit', (code, signal) => {
|
|
if (signal) return;
|
|
if (code && code !== 0) shutdown(code ?? 1);
|
|
});
|
|
return child;
|
|
}
|
|
|
|
let server;
|
|
let web;
|
|
let stopping = false;
|
|
|
|
function shutdown(code = 0) {
|
|
if (stopping) return;
|
|
stopping = true;
|
|
server?.kill('SIGTERM');
|
|
web?.kill('SIGTERM');
|
|
setTimeout(() => process.exit(code), 200).unref();
|
|
}
|
|
|
|
process.on('SIGINT', () => shutdown(0));
|
|
process.on('SIGTERM', () => shutdown(0));
|
|
|
|
console.log('==> 启动 Admin API (memind_adm/server)');
|
|
server = spawnChild('node', ['server/index.mjs'], 'server');
|
|
|
|
setTimeout(() => {
|
|
console.log('==> 启动 vite preview @ http://127.0.0.1:5174');
|
|
web = spawnChild('npm', ['run', 'dev:preview', ...args], 'web');
|
|
}, 800);
|