@house365/comate 0.9.16 → 0.9.17
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.mjs +39 -0
- package/package.json +1 -1
package/bin/cli.mjs
CHANGED
|
@@ -6,15 +6,54 @@
|
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { dirname } from 'node:path';
|
|
8
8
|
import { readFileSync } from 'node:fs';
|
|
9
|
+
import { get } from 'node:https';
|
|
9
10
|
|
|
10
11
|
import { run, skillsInvocation, SKILLS_TIMEOUT_MS } from './init.mjs';
|
|
11
12
|
|
|
13
|
+
// Check npm registry for the latest version and notify if an update is available.
|
|
14
|
+
async function checkForUpdates(currentVersion) {
|
|
15
|
+
return new Promise((resolve) => {
|
|
16
|
+
const req = get('https://registry.npmjs.org/@house365/comate/latest', { timeout: 3000 }, (res) => {
|
|
17
|
+
if (res.statusCode !== 200) {
|
|
18
|
+
resolve();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
let data = '';
|
|
22
|
+
res.on('data', (chunk) => { data += chunk; });
|
|
23
|
+
res.on('end', () => {
|
|
24
|
+
try {
|
|
25
|
+
const pkg = JSON.parse(data);
|
|
26
|
+
const latestVersion = pkg.version;
|
|
27
|
+
if (latestVersion && latestVersion !== currentVersion) {
|
|
28
|
+
console.log('');
|
|
29
|
+
console.log(`\x1b[33m🔔 有新版本可用:${latestVersion} (当前版本:${currentVersion})\x1b[0m`);
|
|
30
|
+
console.log(`\x1b[36m更新命令:npm install -g @house365/comate@latest\x1b[0m`);
|
|
31
|
+
console.log('');
|
|
32
|
+
}
|
|
33
|
+
} catch {
|
|
34
|
+
// Ignore parse errors
|
|
35
|
+
}
|
|
36
|
+
resolve();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
req.on('error', () => resolve());
|
|
40
|
+
req.on('timeout', () => {
|
|
41
|
+
req.destroy();
|
|
42
|
+
resolve();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
12
47
|
const pkgRoot = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
13
48
|
const args = process.argv.slice(2);
|
|
14
49
|
const packageVersion = JSON.parse(readFileSync(`${pkgRoot}/package.json`, 'utf8')).version;
|
|
15
50
|
|
|
16
51
|
if (args[0] === '--version' || args[0] === '-v') {
|
|
17
52
|
console.log(packageVersion);
|
|
53
|
+
// Check for updates in the background, non-blocking
|
|
54
|
+
checkForUpdates(packageVersion).catch(() => {
|
|
55
|
+
// Silently ignore network errors
|
|
56
|
+
});
|
|
18
57
|
process.exit(0);
|
|
19
58
|
}
|
|
20
59
|
|