@myapihq/cli 1.0.24 → 1.0.25
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/dist/commands/update.d.ts +2 -0
- package/dist/commands/update.js +32 -11
- package/package.json +1 -1
- package/src/commands/update.ts +30 -11
package/dist/commands/update.js
CHANGED
|
@@ -5,7 +5,7 @@ import { installSkills } from './setup.js';
|
|
|
5
5
|
const REGISTRY_URL = 'https://registry.npmjs.org/@myapihq/cli/latest';
|
|
6
6
|
const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000; // 24 hours
|
|
7
7
|
// checkForUpdate runs silently in the background on every command.
|
|
8
|
-
//
|
|
8
|
+
// Auto-installs if a newer version is available.
|
|
9
9
|
export async function checkForUpdate(currentVersion) {
|
|
10
10
|
const config = loadConfig();
|
|
11
11
|
const now = Date.now();
|
|
@@ -21,32 +21,53 @@ export async function checkForUpdate(currentVersion) {
|
|
|
21
21
|
if (config) {
|
|
22
22
|
saveConfig({ ...config, last_update_check: now });
|
|
23
23
|
}
|
|
24
|
-
if (latest &&
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
24
|
+
if (latest && isNewer(latest, currentVersion)) {
|
|
25
|
+
info(`\n› New version available (${currentVersion} → ${latest}) — installing…`);
|
|
26
|
+
execSync('npm install -g @myapihq/cli', { stdio: 'pipe' });
|
|
27
|
+
await installSkills();
|
|
28
|
+
success(`› MyAPI CLI updated to ${latest}. Re-run your command.\n`);
|
|
29
|
+
process.exit(0);
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
catch {
|
|
32
|
-
// Network errors are silently ignored.
|
|
33
|
+
// Network or install errors are silently ignored.
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
|
-
// myapi update —
|
|
36
|
+
// myapi update — explicit update, same logic as auto-update.
|
|
36
37
|
export async function update() {
|
|
37
|
-
info('›
|
|
38
|
+
info('› Checking for updates…');
|
|
39
|
+
try {
|
|
40
|
+
const res = await fetch(REGISTRY_URL, { signal: AbortSignal.timeout(5000) });
|
|
41
|
+
if (!res.ok)
|
|
42
|
+
throw new Error(`registry returned ${res.status}`);
|
|
43
|
+
const data = await res.json();
|
|
44
|
+
info(`› Installing @myapihq/cli@${data.version}…`);
|
|
45
|
+
}
|
|
46
|
+
catch { /* proceed anyway */ }
|
|
38
47
|
try {
|
|
39
48
|
execSync('npm install -g @myapihq/cli', { stdio: 'inherit' });
|
|
40
49
|
}
|
|
41
50
|
catch {
|
|
42
|
-
// npm printed its own error; just exit.
|
|
43
51
|
process.exit(1);
|
|
44
52
|
}
|
|
45
53
|
info('› Refreshing skills…');
|
|
46
54
|
await installSkills();
|
|
47
55
|
success('› Up to date.');
|
|
48
56
|
}
|
|
49
|
-
|
|
57
|
+
// latestVersion fetches the current published version for --version display.
|
|
58
|
+
export async function latestVersion() {
|
|
59
|
+
try {
|
|
60
|
+
const res = await fetch(REGISTRY_URL, { signal: AbortSignal.timeout(3000) });
|
|
61
|
+
if (!res.ok)
|
|
62
|
+
return null;
|
|
63
|
+
const data = await res.json();
|
|
64
|
+
return data.version ?? null;
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export function isNewer(latest, current) {
|
|
50
71
|
const toNum = (v) => v.split('.').map(Number);
|
|
51
72
|
const [lMaj, lMin, lPat] = toNum(latest);
|
|
52
73
|
const [cMaj, cMin, cPat] = toNum(current);
|
package/package.json
CHANGED
package/src/commands/update.ts
CHANGED
|
@@ -7,7 +7,7 @@ const REGISTRY_URL = 'https://registry.npmjs.org/@myapihq/cli/latest';
|
|
|
7
7
|
const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000; // 24 hours
|
|
8
8
|
|
|
9
9
|
// checkForUpdate runs silently in the background on every command.
|
|
10
|
-
//
|
|
10
|
+
// Auto-installs if a newer version is available.
|
|
11
11
|
export async function checkForUpdate(currentVersion: string): Promise<void> {
|
|
12
12
|
const config = loadConfig();
|
|
13
13
|
const now = Date.now();
|
|
@@ -26,24 +26,31 @@ export async function checkForUpdate(currentVersion: string): Promise<void> {
|
|
|
26
26
|
saveConfig({ ...config, last_update_check: now });
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
if (latest &&
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
29
|
+
if (latest && isNewer(latest, currentVersion)) {
|
|
30
|
+
info(`\n› New version available (${currentVersion} → ${latest}) — installing…`);
|
|
31
|
+
execSync('npm install -g @myapihq/cli', { stdio: 'pipe' });
|
|
32
|
+
await installSkills();
|
|
33
|
+
success(`› MyAPI CLI updated to ${latest}. Re-run your command.\n`);
|
|
34
|
+
process.exit(0);
|
|
34
35
|
}
|
|
35
36
|
} catch {
|
|
36
|
-
// Network errors are silently ignored.
|
|
37
|
+
// Network or install errors are silently ignored.
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
// myapi update —
|
|
41
|
+
// myapi update — explicit update, same logic as auto-update.
|
|
41
42
|
export async function update(): Promise<void> {
|
|
42
|
-
info('›
|
|
43
|
+
info('› Checking for updates…');
|
|
44
|
+
try {
|
|
45
|
+
const res = await fetch(REGISTRY_URL, { signal: AbortSignal.timeout(5000) });
|
|
46
|
+
if (!res.ok) throw new Error(`registry returned ${res.status}`);
|
|
47
|
+
const data = await res.json() as { version?: string };
|
|
48
|
+
info(`› Installing @myapihq/cli@${data.version}…`);
|
|
49
|
+
} catch { /* proceed anyway */ }
|
|
50
|
+
|
|
43
51
|
try {
|
|
44
52
|
execSync('npm install -g @myapihq/cli', { stdio: 'inherit' });
|
|
45
53
|
} catch {
|
|
46
|
-
// npm printed its own error; just exit.
|
|
47
54
|
process.exit(1);
|
|
48
55
|
}
|
|
49
56
|
info('› Refreshing skills…');
|
|
@@ -51,7 +58,19 @@ export async function update(): Promise<void> {
|
|
|
51
58
|
success('› Up to date.');
|
|
52
59
|
}
|
|
53
60
|
|
|
54
|
-
|
|
61
|
+
// latestVersion fetches the current published version for --version display.
|
|
62
|
+
export async function latestVersion(): Promise<string | null> {
|
|
63
|
+
try {
|
|
64
|
+
const res = await fetch(REGISTRY_URL, { signal: AbortSignal.timeout(3000) });
|
|
65
|
+
if (!res.ok) return null;
|
|
66
|
+
const data = await res.json() as { version?: string };
|
|
67
|
+
return data.version ?? null;
|
|
68
|
+
} catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function isNewer(latest: string, current: string): boolean {
|
|
55
74
|
const toNum = (v: string) => v.split('.').map(Number);
|
|
56
75
|
const [lMaj, lMin, lPat] = toNum(latest);
|
|
57
76
|
const [cMaj, cMin, cPat] = toNum(current);
|