-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.cjs
More file actions
24 lines (19 loc) · 931 Bytes
/
dev.cjs
File metadata and controls
24 lines (19 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Bootstrap: install deps if needed, then start Express + Vite
const { execSync, spawn } = require('child_process');
const { existsSync } = require('fs');
const path = require('path');
const root = __dirname;
if (!existsSync(path.join(root, 'node_modules', '.package-lock.json')) &&
!existsSync(path.join(root, 'node_modules', 'vite'))) {
console.log('Installing dependencies…');
execSync('/usr/local/bin/npm install', { cwd: root, stdio: 'inherit' });
console.log('Done.\n');
}
const vite = path.join(root, 'node_modules', 'vite', 'bin', 'vite.js');
const server = spawn(process.execPath, ['server.js'], { cwd: root, stdio: 'inherit' });
const client = spawn(process.execPath, [vite], { cwd: root, stdio: 'inherit' });
function shutdown() { server.kill(); client.kill(); process.exit(); }
process.on('SIGTERM', shutdown);
process.on('SIGINT', shutdown);
server.on('exit', shutdown);
client.on('exit', shutdown);