copilot-hub-cli 1.1.0 → 1.1.2
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/run.js +74 -27
- package/binaries/darwin-arm64 +0 -0
- package/binaries/darwin-x64 +0 -0
- package/binaries/linux-arm64 +0 -0
- package/binaries/linux-x64 +0 -0
- package/binaries/win32-x64.exe +0 -0
- package/package.json +1 -1
package/bin/run.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Copilot Hub CLI — 跨平台启动器
|
|
5
|
-
*
|
|
5
|
+
* 启动时自动检查更新,然后运行对应平台的 Go 二进制
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
const { spawn } = require('child_process');
|
|
8
|
+
const { spawn, execSync } = require('child_process');
|
|
9
9
|
const path = require('path');
|
|
10
10
|
const os = require('os');
|
|
11
11
|
const fs = require('fs');
|
|
@@ -42,33 +42,80 @@ function getBinaryPath() {
|
|
|
42
42
|
return binaryPath;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
// ★ 自动更新:启动前检查 npm 是否有新版本
|
|
46
|
+
function autoUpdate() {
|
|
47
|
+
// 跳过更新检查:--no-update 参数
|
|
48
|
+
if (process.argv.includes('--no-update')) return;
|
|
46
49
|
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
env: process.env,
|
|
51
|
-
});
|
|
50
|
+
try {
|
|
51
|
+
const pkg = require('../package.json');
|
|
52
|
+
const currentVersion = pkg.version;
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
58
|
-
});
|
|
54
|
+
console.log(`🔍 检查更新... (当前 v${currentVersion})`);
|
|
55
|
+
const latest = execSync('npm view copilot-hub-cli version 2>/dev/null', {
|
|
56
|
+
encoding: 'utf8', timeout: 8000
|
|
57
|
+
}).trim();
|
|
59
58
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
if (latest && latest !== currentVersion && isNewer(latest, currentVersion)) {
|
|
60
|
+
console.log(`🆕 发现新版本 v${latest},正在自动更新...`);
|
|
61
|
+
try {
|
|
62
|
+
execSync('npm install -g copilot-hub-cli@latest', {
|
|
63
|
+
stdio: 'inherit', timeout: 120000
|
|
64
|
+
});
|
|
65
|
+
console.log(`✅ 更新成功!重新启动中...\n`);
|
|
66
|
+
// 用新版本重新启动自己(带 --no-update 防止循环)
|
|
67
|
+
const child = spawn(process.argv[0], [process.argv[1], '--no-update', ...process.argv.slice(2)], {
|
|
68
|
+
stdio: 'inherit', env: process.env
|
|
69
|
+
});
|
|
70
|
+
child.on('exit', (code) => process.exit(code || 0));
|
|
71
|
+
return true; // 表示已接管,主流程不要继续
|
|
72
|
+
} catch (e) {
|
|
73
|
+
console.log(`⚠️ 自动更新失败,使用当前版本继续运行`);
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
console.log(`✅ 已是最新版本 v${currentVersion}`);
|
|
77
|
+
}
|
|
78
|
+
} catch (e) {
|
|
79
|
+
// 网络不通等,静默跳过
|
|
63
80
|
}
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function isNewer(latest, current) {
|
|
85
|
+
const a = latest.split('.').map(Number);
|
|
86
|
+
const b = current.split('.').map(Number);
|
|
87
|
+
for (let i = 0; i < 3; i++) {
|
|
88
|
+
if ((a[i]||0) > (b[i]||0)) return true;
|
|
89
|
+
if ((a[i]||0) < (b[i]||0)) return false;
|
|
72
90
|
}
|
|
73
|
-
|
|
74
|
-
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 先检查更新
|
|
95
|
+
if (autoUpdate()) {
|
|
96
|
+
// autoUpdate 已接管进程,等待新版本启动
|
|
97
|
+
} else {
|
|
98
|
+
// 正常启动
|
|
99
|
+
const binaryPath = getBinaryPath();
|
|
100
|
+
|
|
101
|
+
const child = spawn(binaryPath, process.argv.slice(2).filter(a => a !== '--no-update'), {
|
|
102
|
+
stdio: 'inherit',
|
|
103
|
+
env: process.env,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
['SIGINT', 'SIGTERM', 'SIGHUP'].forEach(signal => {
|
|
107
|
+
process.on(signal, () => { child.kill(signal); });
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
child.on('exit', (code, signal) => {
|
|
111
|
+
process.exit(signal ? 1 : (code || 0));
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
child.on('error', (err) => {
|
|
115
|
+
console.error(`❌ 启动失败: ${err.message}`);
|
|
116
|
+
if (err.code === 'EACCES') {
|
|
117
|
+
console.error(` 请运行: chmod +x "${binaryPath}"`);
|
|
118
|
+
}
|
|
119
|
+
process.exit(1);
|
|
120
|
+
});
|
|
121
|
+
}
|
package/binaries/darwin-arm64
CHANGED
|
Binary file
|
package/binaries/darwin-x64
CHANGED
|
Binary file
|
package/binaries/linux-arm64
CHANGED
|
Binary file
|
package/binaries/linux-x64
CHANGED
|
Binary file
|
package/binaries/win32-x64.exe
CHANGED
|
Binary file
|