cdp-tunnel 1.1.0 → 1.2.0
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 +77 -43
- package/package.json +1 -1
package/cli/index.js
CHANGED
|
@@ -358,64 +358,83 @@ program
|
|
|
358
358
|
program
|
|
359
359
|
.command('update')
|
|
360
360
|
.description('自动更新 cdp-tunnel 并重启服务')
|
|
361
|
-
.option('-p, --port <port>', '
|
|
362
|
-
.option('-w, --watchdog', '
|
|
361
|
+
.option('-p, --port <port>', '指定端口', parseInt)
|
|
362
|
+
.option('-w, --watchdog', '启用看门狗')
|
|
363
363
|
.action(async (options) => {
|
|
364
364
|
const config = getConfig();
|
|
365
365
|
const wasRunning = isServerRunning();
|
|
366
366
|
const savedPort = options.port || config.port;
|
|
367
367
|
const savedWatchdog = options.watchdog;
|
|
368
|
-
|
|
369
|
-
console.log('');
|
|
370
|
-
log('cyan', '⬆ 正在检查更新...');
|
|
371
|
-
|
|
368
|
+
|
|
372
369
|
try {
|
|
373
|
-
|
|
374
|
-
|
|
370
|
+
log('cyan', '🔍 检查更新...');
|
|
371
|
+
let latestVersion;
|
|
372
|
+
try {
|
|
373
|
+
latestVersion = execSync('npm view cdp-tunnel version', {
|
|
374
|
+
encoding: 'utf8',
|
|
375
|
+
timeout: 30000
|
|
376
|
+
}).trim();
|
|
377
|
+
} catch (err) {
|
|
378
|
+
log('red', '❌ 无法连接 npm registry: ' + err.message);
|
|
379
|
+
process.exit(1);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const localVersion = JSON.parse(fs.readFileSync(
|
|
383
|
+
path.join(__dirname, '..', 'package.json'), 'utf8'
|
|
384
|
+
)).version;
|
|
385
|
+
|
|
375
386
|
log('gray', ' 当前版本: ' + localVersion);
|
|
376
|
-
log('gray', ' 最新版本: ' +
|
|
377
|
-
|
|
387
|
+
log('gray', ' 最新版本: ' + latestVersion);
|
|
388
|
+
|
|
389
|
+
if (localVersion === latestVersion) {
|
|
390
|
+
log('green', '✅ 已是最新版本 (' + localVersion + ')');
|
|
391
|
+
if (wasRunning) {
|
|
392
|
+
log('cyan', ' 服务器仍在运行中');
|
|
393
|
+
}
|
|
394
|
+
process.exit(0);
|
|
395
|
+
}
|
|
396
|
+
|
|
378
397
|
if (wasRunning) {
|
|
379
|
-
log('yellow', '
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
process.kill(pid, 'SIGTERM');
|
|
383
|
-
fs.unlinkSync(PID_FILE);
|
|
398
|
+
log('yellow', '⏸ 停止服务器...');
|
|
399
|
+
const pid = getServerPid();
|
|
400
|
+
if (pid) {
|
|
401
|
+
try { process.kill(pid, 'SIGTERM'); } catch {}
|
|
384
402
|
await new Promise(r => setTimeout(r, 1500));
|
|
385
|
-
log('green', ' ✓ 服务器已停止');
|
|
386
|
-
} catch (e) {
|
|
387
|
-
log('yellow', ' ⚠ 停止服务器失败: ' + e.message);
|
|
388
403
|
}
|
|
389
404
|
}
|
|
390
|
-
|
|
391
|
-
log('cyan', '
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
405
|
+
|
|
406
|
+
log('cyan', '📦 更新中 (' + localVersion + ' → ' + latestVersion + ')...');
|
|
407
|
+
try {
|
|
408
|
+
execSync('npm update -g cdp-tunnel', {
|
|
409
|
+
stdio: 'inherit',
|
|
410
|
+
timeout: 120000
|
|
411
|
+
});
|
|
412
|
+
} catch (err) {
|
|
413
|
+
log('red', '❌ 更新失败: ' + err.message);
|
|
414
|
+
process.exit(1);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const newVersion = JSON.parse(fs.readFileSync(
|
|
418
|
+
path.join(__dirname, '..', 'package.json'), 'utf8'
|
|
419
|
+
)).version;
|
|
420
|
+
|
|
421
|
+
if (newVersion !== localVersion) {
|
|
422
|
+
log('green', '✅ 已更新: ' + localVersion + ' → ' + newVersion);
|
|
397
423
|
} else {
|
|
398
|
-
log('
|
|
424
|
+
log('yellow', '⚠ 版本未变化,可能需要手动更新');
|
|
399
425
|
}
|
|
400
|
-
|
|
401
|
-
ensureConfigDir();
|
|
402
|
-
cleanupLogFile();
|
|
403
|
-
startServer(savedPort, savedWatchdog);
|
|
404
|
-
log('green', ' ✓ 服务器已重启 (端口: ' + savedPort + ')');
|
|
405
|
-
console.log('');
|
|
406
|
-
} catch (e) {
|
|
407
|
-
log('red', '✗ 更新失败: ' + e.message);
|
|
408
|
-
console.log('');
|
|
426
|
+
|
|
409
427
|
if (wasRunning) {
|
|
410
|
-
log('
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
} catch (re) {
|
|
416
|
-
log('red', '✗ 恢复失败,请手动启动: cdp-tunnel start');
|
|
417
|
-
}
|
|
428
|
+
log('cyan', '🔄 重启服务器...');
|
|
429
|
+
startServer(savedPort, savedWatchdog, config.autoRestart);
|
|
430
|
+
log('green', '✅ 服务器已重启');
|
|
431
|
+
} else {
|
|
432
|
+
log('cyan', ' 运行 cdp-tunnel start 启动服务器');
|
|
418
433
|
}
|
|
434
|
+
|
|
435
|
+
process.exit(0);
|
|
436
|
+
} catch (err) {
|
|
437
|
+
log('red', '❌ 更新出错: ' + err.message);
|
|
419
438
|
process.exit(1);
|
|
420
439
|
}
|
|
421
440
|
});
|
|
@@ -576,4 +595,19 @@ program
|
|
|
576
595
|
}
|
|
577
596
|
});
|
|
578
597
|
|
|
598
|
+
program.addHelpText('after', `
|
|
599
|
+
|
|
600
|
+
常用命令:
|
|
601
|
+
$ cdp-tunnel start 启动服务(自动启动 Chrome)
|
|
602
|
+
$ cdp-tunnel start --auto-restart Chrome 断连时自动重启
|
|
603
|
+
$ cdp-tunnel start --watchdog 服务崩溃时自动重启
|
|
604
|
+
$ cdp-tunnel status 查看状态
|
|
605
|
+
$ cdp-tunnel update 检查并更新
|
|
606
|
+
$ cdp-tunnel extension 安装 Chrome 扩展
|
|
607
|
+
|
|
608
|
+
快速开始:
|
|
609
|
+
$ npm install -g cdp-tunnel
|
|
610
|
+
$ cdp-tunnel start # 一行命令搞定!
|
|
611
|
+
`);
|
|
612
|
+
|
|
579
613
|
program.parse();
|