-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart.js
More file actions
42 lines (35 loc) · 1.18 KB
/
Copy pathstart.js
File metadata and controls
42 lines (35 loc) · 1.18 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
/**
* 跨平台启动脚本
* 捕获 Electron stdout/stderr 写入日志文件,避免 Chromium 在 cwd 生成 PID 日志
*/
const { spawn } = require('child_process');
const fs = require('fs');
const path = require('path');
const isWin = process.platform === 'win32';
// 创建 wyp/log 目录
const logDir = path.join(__dirname, 'wyp', 'log');
fs.mkdirSync(logDir, { recursive: true });
// 清空旧日志
try {
for (const f of fs.readdirSync(logDir)) {
if (f.endsWith('.log')) fs.writeFileSync(path.join(logDir, f), '', 'utf-8');
}
} catch (err) {
console.warn('[start.js] 清空日志失败:', err.message);
}
const logFile = path.join(logDir, 'electron.log');
const logStream = fs.createWriteStream(logFile, { flags: 'a' });
const cmd = isWin ? 'chcp 65001 > nul && electron .' : 'electron .';
const child = spawn(cmd, { shell: true, stdio: ['inherit', 'pipe', 'pipe'] });
child.stdout.pipe(logStream);
child.stderr.pipe(logStream);
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
child.on('close', (code) => {
logStream.end();
process.exit(code ?? 0);
});
child.on('error', (err) => {
console.error('启动失败:', err.message);
process.exit(1);
});