@aiyiran/myclaw 1.0.57 → 1.0.60
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/index.js +47 -13
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -678,36 +678,70 @@ function runUpdate() {
|
|
|
678
678
|
console.log('[' + colors.blue + 'MyClaw' + colors.nc + '] ' + colors.blue + '强制升级 MyClaw' + colors.nc);
|
|
679
679
|
console.log(bar);
|
|
680
680
|
console.log('');
|
|
681
|
-
|
|
682
|
-
console.log('');
|
|
683
|
-
|
|
681
|
+
|
|
684
682
|
const { execSync } = require('child_process');
|
|
685
|
-
const
|
|
683
|
+
const registry = 'https://registry.npmjs.org';
|
|
684
|
+
const pkg = '@aiyiran/myclaw';
|
|
686
685
|
const maxRetries = 3;
|
|
687
686
|
|
|
687
|
+
// 获取当前版本
|
|
688
|
+
let currentVersion = 'unknown';
|
|
689
|
+
try {
|
|
690
|
+
currentVersion = require(path.join(__dirname, 'package.json')).version;
|
|
691
|
+
} catch {}
|
|
692
|
+
|
|
688
693
|
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
689
694
|
try {
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
695
|
+
if (attempt > 1) {
|
|
696
|
+
console.log('(第 ' + attempt + ' 次尝试)');
|
|
697
|
+
console.log('');
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// 第一步:查询最新版的 tarball URL
|
|
701
|
+
console.log('> 查询最新版本...');
|
|
702
|
+
const tarball = execSync(
|
|
703
|
+
'npm view ' + pkg + ' dist.tarball --registry ' + registry,
|
|
704
|
+
{ encoding: 'utf8', timeout: 15000 }
|
|
705
|
+
).trim();
|
|
706
|
+
|
|
707
|
+
const latestVersion = execSync(
|
|
708
|
+
'npm view ' + pkg + ' version --registry ' + registry,
|
|
709
|
+
{ encoding: 'utf8', timeout: 15000 }
|
|
710
|
+
).trim();
|
|
711
|
+
|
|
712
|
+
console.log(' 当前版本: v' + currentVersion);
|
|
713
|
+
console.log(' 最新版本: v' + latestVersion);
|
|
714
|
+
console.log(' Tarball: ' + tarball);
|
|
694
715
|
console.log('');
|
|
695
|
-
|
|
696
|
-
|
|
716
|
+
|
|
717
|
+
if (currentVersion === latestVersion) {
|
|
718
|
+
console.log('[' + colors.green + '已是最新' + colors.nc + '] 无需升级');
|
|
719
|
+
break;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// 第二步:直接从 tarball URL 安装(绕过 @latest 解析)
|
|
723
|
+
console.log('> 从 tarball 直接安装...');
|
|
724
|
+
execSync('npm install -g ' + tarball, { stdio: 'inherit', timeout: 60000 });
|
|
725
|
+
|
|
726
|
+
console.log('');
|
|
727
|
+
console.log('[' + colors.green + '成功' + colors.nc + '] MyClaw 已升级: v' + currentVersion + ' → v' + latestVersion);
|
|
728
|
+
|
|
697
729
|
if (detectPlatform() === 'wsl' || detectPlatform() === 'linux' || detectPlatform() === 'mac') {
|
|
698
730
|
console.log('');
|
|
699
731
|
console.log('如果需要同时升级 OpenClaw 核心,请运行:');
|
|
700
732
|
console.log(' ' + colors.yellow + 'myclaw install' + colors.nc);
|
|
701
733
|
}
|
|
702
|
-
break;
|
|
734
|
+
break;
|
|
703
735
|
} catch (err) {
|
|
704
736
|
if (attempt < maxRetries) {
|
|
705
737
|
console.log('');
|
|
706
|
-
console.log('[' + colors.yellow + '重试' + colors.nc + ']
|
|
707
|
-
execSync('sleep
|
|
738
|
+
console.log('[' + colors.yellow + '重试' + colors.nc + '] 8 秒后重试 (' + attempt + '/' + maxRetries + ')...');
|
|
739
|
+
execSync('sleep 8', { stdio: 'ignore' });
|
|
708
740
|
} else {
|
|
709
741
|
console.log('');
|
|
710
742
|
console.log('[' + colors.red + '错误' + colors.nc + '] 升级失败: ' + err.message);
|
|
743
|
+
console.log('');
|
|
744
|
+
console.log('手动升级: npm install -g ' + pkg + '@latest --registry ' + registry);
|
|
711
745
|
}
|
|
712
746
|
}
|
|
713
747
|
}
|