cc-goto-work 0.8.2 → 0.8.3
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/bin/cli.js +120 -3
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -69,7 +69,8 @@ function printMenu() {
|
|
|
69
69
|
print(` ${colors.cyan}2${colors.reset} - 仅下载二进制文件`);
|
|
70
70
|
print(` ${colors.cyan}3${colors.reset} - 仅配置 API 设置`);
|
|
71
71
|
print(` ${colors.cyan}4${colors.reset} - 仅配置 Claude Code Hook`);
|
|
72
|
-
print(` ${colors.cyan}5${colors.reset} - ${colors.
|
|
72
|
+
print(` ${colors.cyan}5${colors.reset} - ${colors.blue}检查更新${colors.reset}`);
|
|
73
|
+
print(` ${colors.cyan}6${colors.reset} - ${colors.red}卸载 cc-goto-work${colors.reset}`);
|
|
73
74
|
print(` ${colors.cyan}0${colors.reset} - 退出`);
|
|
74
75
|
print('');
|
|
75
76
|
}
|
|
@@ -197,6 +198,10 @@ async function downloadBinary(version, platformStr) {
|
|
|
197
198
|
fs.chmodSync(destPath, 0o755);
|
|
198
199
|
}
|
|
199
200
|
|
|
201
|
+
// Save version info
|
|
202
|
+
const versionFile = path.join(INSTALL_DIR, '.version');
|
|
203
|
+
fs.writeFileSync(versionFile, version);
|
|
204
|
+
|
|
200
205
|
printSuccess(`二进制文件已下载到: ${destPath}`);
|
|
201
206
|
return destPath;
|
|
202
207
|
}
|
|
@@ -417,6 +422,115 @@ async function configureHookOnly(rl) {
|
|
|
417
422
|
return true;
|
|
418
423
|
}
|
|
419
424
|
|
|
425
|
+
// ============================================================================
|
|
426
|
+
// Update
|
|
427
|
+
// ============================================================================
|
|
428
|
+
|
|
429
|
+
const VERSION_FILE = path.join(INSTALL_DIR, '.version');
|
|
430
|
+
|
|
431
|
+
function getInstalledVersion() {
|
|
432
|
+
try {
|
|
433
|
+
if (fs.existsSync(VERSION_FILE)) {
|
|
434
|
+
return fs.readFileSync(VERSION_FILE, 'utf8').trim();
|
|
435
|
+
}
|
|
436
|
+
} catch (e) {
|
|
437
|
+
// Ignore
|
|
438
|
+
}
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function saveInstalledVersion(version) {
|
|
443
|
+
try {
|
|
444
|
+
fs.mkdirSync(INSTALL_DIR, { recursive: true });
|
|
445
|
+
fs.writeFileSync(VERSION_FILE, version);
|
|
446
|
+
} catch (e) {
|
|
447
|
+
// Ignore
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function compareVersions(v1, v2) {
|
|
452
|
+
// Remove 'v' prefix if present
|
|
453
|
+
const normalize = (v) => v.replace(/^v/, '').split('.').map(Number);
|
|
454
|
+
const parts1 = normalize(v1);
|
|
455
|
+
const parts2 = normalize(v2);
|
|
456
|
+
|
|
457
|
+
for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
|
|
458
|
+
const p1 = parts1[i] || 0;
|
|
459
|
+
const p2 = parts2[i] || 0;
|
|
460
|
+
if (p1 > p2) return 1;
|
|
461
|
+
if (p1 < p2) return -1;
|
|
462
|
+
}
|
|
463
|
+
return 0;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
async function checkUpdate(rl) {
|
|
467
|
+
printStep('检查更新...');
|
|
468
|
+
print('');
|
|
469
|
+
|
|
470
|
+
const platformStr = detectPlatform();
|
|
471
|
+
if (!platformStr) {
|
|
472
|
+
printError(`不支持的平台: ${os.platform()} ${os.arch()}`);
|
|
473
|
+
return false;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
const binaryName = getBinaryName(platformStr);
|
|
477
|
+
const binaryPath = path.join(INSTALL_DIR, binaryName);
|
|
478
|
+
|
|
479
|
+
if (!fs.existsSync(binaryPath)) {
|
|
480
|
+
printWarning('未检测到安装,请先安装');
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// Get installed version
|
|
485
|
+
const installedVersion = getInstalledVersion();
|
|
486
|
+
if (installedVersion) {
|
|
487
|
+
print(` 当前版本: ${installedVersion}`);
|
|
488
|
+
} else {
|
|
489
|
+
print(` 当前版本: ${colors.yellow}未知${colors.reset}`);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// Get latest version
|
|
493
|
+
printStep('获取最新版本...');
|
|
494
|
+
let latestVersion;
|
|
495
|
+
try {
|
|
496
|
+
latestVersion = await getLatestVersion();
|
|
497
|
+
print(` 最新版本: ${latestVersion}`);
|
|
498
|
+
} catch (e) {
|
|
499
|
+
printError(`获取版本失败: ${e.message}`);
|
|
500
|
+
return false;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
print('');
|
|
504
|
+
|
|
505
|
+
// Compare versions
|
|
506
|
+
if (installedVersion && compareVersions(installedVersion, latestVersion) >= 0) {
|
|
507
|
+
printSuccess('已是最新版本,无需更新');
|
|
508
|
+
return true;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// Ask to update
|
|
512
|
+
const updateMsg = installedVersion
|
|
513
|
+
? `发现新版本!是否从 ${installedVersion} 更新到 ${latestVersion}?`
|
|
514
|
+
: `是否更新到 ${latestVersion}?`;
|
|
515
|
+
|
|
516
|
+
if (!(await promptConfirm(rl, updateMsg))) {
|
|
517
|
+
print('更新已取消');
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// Download new version
|
|
522
|
+
print('');
|
|
523
|
+
try {
|
|
524
|
+
await downloadBinary(latestVersion, platformStr);
|
|
525
|
+
saveInstalledVersion(latestVersion);
|
|
526
|
+
printSuccess(`已更新到 ${latestVersion}`);
|
|
527
|
+
return true;
|
|
528
|
+
} catch (e) {
|
|
529
|
+
printError(`更新失败: ${e.message}`);
|
|
530
|
+
return false;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
420
534
|
// ============================================================================
|
|
421
535
|
// Uninstall
|
|
422
536
|
// ============================================================================
|
|
@@ -537,7 +651,7 @@ async function main() {
|
|
|
537
651
|
while (true) {
|
|
538
652
|
printMenu();
|
|
539
653
|
|
|
540
|
-
const choice = await question(rl, '请输入选项 (0-
|
|
654
|
+
const choice = await question(rl, '请输入选项 (0-6): ');
|
|
541
655
|
|
|
542
656
|
let success = false;
|
|
543
657
|
|
|
@@ -555,6 +669,9 @@ async function main() {
|
|
|
555
669
|
success = await configureHookOnly(rl);
|
|
556
670
|
break;
|
|
557
671
|
case '5':
|
|
672
|
+
success = await checkUpdate(rl);
|
|
673
|
+
break;
|
|
674
|
+
case '6':
|
|
558
675
|
success = await uninstall(rl);
|
|
559
676
|
break;
|
|
560
677
|
case '0':
|
|
@@ -565,7 +682,7 @@ async function main() {
|
|
|
565
682
|
rl.close();
|
|
566
683
|
return;
|
|
567
684
|
default:
|
|
568
|
-
printError('无效选项,请输入 0-
|
|
685
|
+
printError('无效选项,请输入 0-6');
|
|
569
686
|
continue;
|
|
570
687
|
}
|
|
571
688
|
|