cdp-tunnel 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/index.js +19 -1
- package/package.json +1 -1
package/cli/index.js
CHANGED
|
@@ -11,6 +11,7 @@ const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
|
11
11
|
const PID_FILE = path.join(CONFIG_DIR, 'server.pid');
|
|
12
12
|
const LOG_FILE = path.join(CONFIG_DIR, 'server.log');
|
|
13
13
|
const EXTENSION_STATE_FILE = path.join(CONFIG_DIR, 'extension-state.json');
|
|
14
|
+
const MAX_LOG_SIZE = 10 * 1024 * 1024; // 10MB
|
|
14
15
|
|
|
15
16
|
const program = new Command();
|
|
16
17
|
|
|
@@ -38,6 +39,22 @@ function ensureConfigDir() {
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
function cleanupLogFile() {
|
|
43
|
+
try {
|
|
44
|
+
if (fs.existsSync(LOG_FILE)) {
|
|
45
|
+
const stats = fs.statSync(LOG_FILE);
|
|
46
|
+
if (stats.size > MAX_LOG_SIZE) {
|
|
47
|
+
fs.writeFileSync(LOG_FILE, '');
|
|
48
|
+
console.log('');
|
|
49
|
+
log('yellow', '⚠ 日志文件超过 10MB,已清空');
|
|
50
|
+
console.log('');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} catch (e) {
|
|
54
|
+
// 清理失败不影响启动
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
41
58
|
function getConfig() {
|
|
42
59
|
ensureConfigDir();
|
|
43
60
|
if (fs.existsSync(CONFIG_FILE)) {
|
|
@@ -149,7 +166,8 @@ program
|
|
|
149
166
|
}
|
|
150
167
|
|
|
151
168
|
ensureConfigDir();
|
|
152
|
-
|
|
169
|
+
cleanupLogFile();
|
|
170
|
+
|
|
153
171
|
const serverPath = path.join(__dirname, '..', 'server', 'proxy-server.js');
|
|
154
172
|
|
|
155
173
|
const child = spawn('node', [serverPath], {
|