yingclaw 2.1.0 → 2.1.1
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 +76 -0
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -825,6 +825,56 @@ program
|
|
|
825
825
|
}
|
|
826
826
|
});
|
|
827
827
|
|
|
828
|
+
program
|
|
829
|
+
.command('update')
|
|
830
|
+
.description('检查并更新 yingclaw 到最新版本')
|
|
831
|
+
.action(async () => {
|
|
832
|
+
const chalk = (await import('chalk')).default;
|
|
833
|
+
const ora = (await import('ora')).default;
|
|
834
|
+
const boxen = (await import('boxen')).default;
|
|
835
|
+
|
|
836
|
+
console.log(await getBanner());
|
|
837
|
+
|
|
838
|
+
const spinner = ora('检查最新版本...').start();
|
|
839
|
+
const latest = await checkForUpdate();
|
|
840
|
+
|
|
841
|
+
if (!latest) {
|
|
842
|
+
spinner.warn(chalk.yellow('无法获取版本信息,请检查网络'));
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
const current = pkg.version;
|
|
847
|
+
if (compareVersions(latest, current) <= 0) {
|
|
848
|
+
spinner.succeed(chalk.green(`已是最新版本 v${current}`));
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
spinner.succeed(chalk.green(`发现新版本 v${latest}(当前 v${current})`));
|
|
853
|
+
|
|
854
|
+
const yes = await confirm({ message: `升级到 v${latest}?`, default: true });
|
|
855
|
+
if (!yes) {
|
|
856
|
+
console.log(chalk.dim('已取消'));
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
const installCmd = buildClaudeInstallCommand('vpn');
|
|
861
|
+
const upgradeCmd = { command: installCmd.command, args: [...installCmd.args.slice(0, -1), 'yingclaw@latest'] };
|
|
862
|
+
|
|
863
|
+
console.log(chalk.dim('\n升级中...\n'));
|
|
864
|
+
const result = spawnSync(upgradeCmd.command, upgradeCmd.args, { stdio: 'inherit' });
|
|
865
|
+
|
|
866
|
+
if (result.status === 0) {
|
|
867
|
+
console.log(boxen(
|
|
868
|
+
chalk.bold(`yingclaw 已升级到 v${latest}\n\n`) +
|
|
869
|
+
chalk.dim('重新运行 ') + chalk.cyan('claw') + chalk.dim(' 使新版本生效'),
|
|
870
|
+
{ padding: { top: 0, bottom: 0, left: 2, right: 2 }, borderStyle: 'round', borderColor: 'green', margin: { top: 1, bottom: 1 } }
|
|
871
|
+
));
|
|
872
|
+
} else {
|
|
873
|
+
console.log(chalk.red('\n升级失败,请手动运行:'));
|
|
874
|
+
console.log(chalk.cyan('npm install -g yingclaw@latest'));
|
|
875
|
+
}
|
|
876
|
+
});
|
|
877
|
+
|
|
828
878
|
async function renderStatusBar(apiStatus) {
|
|
829
879
|
const chalk = (await import('chalk')).default;
|
|
830
880
|
const config = loadConfig();
|
|
@@ -855,6 +905,30 @@ async function renderStatusBar(apiStatus) {
|
|
|
855
905
|
return config ? ` ${cfgPart}` : ` ${claudeIcon} ${claudeText} ${cfgPart}`;
|
|
856
906
|
}
|
|
857
907
|
|
|
908
|
+
async function checkForUpdate() {
|
|
909
|
+
try {
|
|
910
|
+
const controller = new AbortController();
|
|
911
|
+
const timeout = setTimeout(() => controller.abort(), 5000);
|
|
912
|
+
const res = await fetch(`https://registry.npmjs.org/yingclaw/latest`, { signal: controller.signal });
|
|
913
|
+
clearTimeout(timeout);
|
|
914
|
+
if (!res.ok) return null;
|
|
915
|
+
const data = await res.json();
|
|
916
|
+
return data.version || null;
|
|
917
|
+
} catch {
|
|
918
|
+
return null;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
function compareVersions(a, b) {
|
|
923
|
+
const pa = a.split('.').map(Number);
|
|
924
|
+
const pb = b.split('.').map(Number);
|
|
925
|
+
for (let i = 0; i < 3; i++) {
|
|
926
|
+
if ((pa[i] || 0) > (pb[i] || 0)) return 1;
|
|
927
|
+
if ((pa[i] || 0) < (pb[i] || 0)) return -1;
|
|
928
|
+
}
|
|
929
|
+
return 0;
|
|
930
|
+
}
|
|
931
|
+
|
|
858
932
|
// 缓存上次校验的 config 哈希和结果,避免每次回菜单都重检
|
|
859
933
|
let lastCheckedHash = null;
|
|
860
934
|
let lastCheckResult; // undefined / true / false / null
|
|
@@ -885,6 +959,7 @@ async function runAdvancedMenu(chalk, hasConfig) {
|
|
|
885
959
|
{ name: '↩️ 恢复 Claude Code 终端默认', value: 'code-reset' },
|
|
886
960
|
{ name: '↩️ 恢复 Claude 桌面默认', value: 'desktop-reset' },
|
|
887
961
|
{ name: '🗑 清除所有 yingclaw 配置', value: 'reset' },
|
|
962
|
+
{ name: '⬆️ 检查更新', value: 'update' },
|
|
888
963
|
{ name: chalk.dim('↩ 返回主菜单'), value: '__BACK__' },
|
|
889
964
|
],
|
|
890
965
|
});
|
|
@@ -986,6 +1061,7 @@ async function runMenu() {
|
|
|
986
1061
|
'desktop-reset': 'desktop-reset',
|
|
987
1062
|
status: 'status',
|
|
988
1063
|
reset: 'reset',
|
|
1064
|
+
update: 'update',
|
|
989
1065
|
};
|
|
990
1066
|
|
|
991
1067
|
// 执行子命令(用 spawn 隔离,避免 commander 对 program 的副作用)
|