-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathdev-server-command.mjs
More file actions
51 lines (46 loc) · 1.16 KB
/
dev-server-command.mjs
File metadata and controls
51 lines (46 loc) · 1.16 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
import { spawnSync } from 'node:child_process'
export function createChatlabStartCommand({ serverDir, backendPort, nodeExecutable = process.execPath }) {
return {
command: nodeExecutable,
args: [
'--watch',
'--import',
'tsx',
'src/cli.ts',
'start',
'--headless',
'--no-open',
'--port',
String(backendPort),
],
options: {
cwd: serverDir,
stdio: ['ignore', 'pipe', 'pipe'],
env: { ...process.env },
detached: true,
},
}
}
export function terminateChatlabStartProcess(
childProcess,
{ platform = process.platform, killProcess = process.kill, spawnSyncFn = spawnSync } = {}
) {
if (!childProcess) return
if (childProcess.exitCode !== null || childProcess.signalCode !== null) return
const pid = childProcess.pid
if (!pid) {
childProcess.kill('SIGTERM')
return
}
if (platform === 'win32') {
const result = spawnSyncFn('taskkill', ['/PID', String(pid), '/T', '/F'], { stdio: 'ignore' })
if (result.status === 0) return
childProcess.kill('SIGTERM')
return
}
try {
killProcess(-pid, 'SIGTERM')
} catch {
childProcess.kill('SIGTERM')
}
}