-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.ts
More file actions
66 lines (56 loc) · 1.6 KB
/
dev.ts
File metadata and controls
66 lines (56 loc) · 1.6 KB
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
// dev.ts
// Simple development launcher: kernel + HTTP server → frontend
import { spawn } from 'child_process';
import http from 'http';
// ========================
// Helper: start a process
// ========================
function startProcess(name: string, command: string, cwd?: string) {
console.log(`🚀 starting ${name}`);
const proc = spawn(command, {
shell: true,
stdio: 'inherit',
cwd,
});
proc.on('exit', code =>
console.log(`❌ ${name} exited (${code})`)
);
}
// ========================
// Helper: wait for HTTP server
// ========================
function waitForServer(url: string, timeout = 10000): Promise<void> {
return new Promise((resolve, reject) => {
const start = Date.now();
const check = () => {
http.get(url, res => {
if (res.statusCode === 200) return resolve();
retry();
}).on('error', retry);
function retry() {
if (Date.now() - start > timeout) return reject(new Error('Server did not respond in time'));
setTimeout(check, 200);
}
};
check();
});
}
// ========================
// 1️⃣ Start kernel (backend included)
// ========================
startProcess('kernel', 'npx tsx start.ts');
// ========================
// 2️⃣ Wait for HTTP server to be ready
// ========================
waitForServer('http://localhost:3001/api/health', 30000)
.then(() => {
// ========================
// 3️⃣ Start frontend
// ========================
startProcess(
'frontend',
'npm run dev -- --host',
'./apps/dashboard'
);
})
.catch(err => console.error(err));