Skip to content

Commit 4c316db

Browse files
committed
fix: 修复npm run electron中预设路径
1 parent def9ccc commit 4c316db

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env node
2+
import { spawn } from 'node:child_process'
3+
import path from 'node:path'
4+
5+
const timeoutMs = Number(process.env.ELECTRON_TIMEOUT_MS ?? 30 * 60 * 1000) // 30 minutes
6+
const workdir = path.resolve(process.argv[2] ?? 'packages/gui')
7+
const command = process.platform === 'win32' ? 'npm.cmd' : 'npm'
8+
9+
console.log(`Starting npm run electron in ${workdir} with ${timeoutMs / 60000} minute timeout...`)
10+
11+
const child = spawn(command, ['run', 'electron'], {
12+
cwd: workdir,
13+
stdio: 'inherit',
14+
})
15+
16+
let timedOut = false
17+
18+
const timer = setTimeout(() => {
19+
timedOut = true
20+
console.log(`\n⏱ Electron run completed ${timeoutMs / 60000} minutes without error, terminating...`)
21+
child.kill('SIGTERM')
22+
setTimeout(() => {
23+
if (!child.killed)
24+
child.kill('SIGKILL')
25+
}, 5000)
26+
}, timeoutMs)
27+
28+
child.on('exit', (code, signal) => {
29+
clearTimeout(timer)
30+
if (timedOut) {
31+
console.log('✅ 程序运行正常')
32+
process.exit(0)
33+
} else {
34+
console.log('❌ 程序运行不正常')
35+
process.exit(1)
36+
}
37+
})
38+
39+
child.on('error', (err) => {
40+
clearTimeout(timer)
41+
console.error('Failed to start electron:', err)
42+
process.exit(1)
43+
})

0 commit comments

Comments
 (0)