openhome-cli 0.1.6 → 0.1.7
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/cli.js +46 -11
- package/package.json +4 -1
- package/src/cli.ts +64 -11
package/dist/cli.js
CHANGED
|
@@ -3216,6 +3216,39 @@ try {
|
|
|
3216
3216
|
version = pkg.version ?? version;
|
|
3217
3217
|
} catch {
|
|
3218
3218
|
}
|
|
3219
|
+
async function checkForUpdates() {
|
|
3220
|
+
if (process.env.OPENHOME_NO_UPDATE === "1") return;
|
|
3221
|
+
try {
|
|
3222
|
+
const res = await fetch("https://registry.npmjs.org/openhome-cli/latest", {
|
|
3223
|
+
signal: AbortSignal.timeout(2e3)
|
|
3224
|
+
});
|
|
3225
|
+
const data = await res.json();
|
|
3226
|
+
const latest = data.version;
|
|
3227
|
+
if (!latest || latest === version) return;
|
|
3228
|
+
const toNum = (v) => v.split(".").map(Number).reduce((a, n) => a * 1e3 + n, 0);
|
|
3229
|
+
if (toNum(latest) <= toNum(version)) return;
|
|
3230
|
+
const arg1 = process.argv[1] ?? "";
|
|
3231
|
+
const isNpx = arg1.includes("_npx") || arg1.includes(".npm/") || (process.env.npm_execpath ?? "").includes("npx");
|
|
3232
|
+
if (isNpx) {
|
|
3233
|
+
const { execFileSync } = await import("child_process");
|
|
3234
|
+
execFileSync(
|
|
3235
|
+
"npx",
|
|
3236
|
+
[`openhome-cli@${latest}`, ...process.argv.slice(2)],
|
|
3237
|
+
{ stdio: "inherit", env: { ...process.env, OPENHOME_NO_UPDATE: "1" } }
|
|
3238
|
+
);
|
|
3239
|
+
process.exit(0);
|
|
3240
|
+
} else {
|
|
3241
|
+
const { default: chalk14 } = await import("chalk");
|
|
3242
|
+
console.log(
|
|
3243
|
+
chalk14.yellow(
|
|
3244
|
+
` Update available: v${version} \u2192 v${latest} Run: npm install -g openhome-cli@latest
|
|
3245
|
+
`
|
|
3246
|
+
)
|
|
3247
|
+
);
|
|
3248
|
+
}
|
|
3249
|
+
} catch {
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3219
3252
|
async function ensureLoggedIn() {
|
|
3220
3253
|
const { getApiKey: getApiKey2 } = await import("./store-USDMWKXY.js");
|
|
3221
3254
|
const key = getApiKey2();
|
|
@@ -3379,14 +3412,16 @@ program.command("set-jwt [token]").description(
|
|
|
3379
3412
|
).action(async (token) => {
|
|
3380
3413
|
await setJwtCommand(token);
|
|
3381
3414
|
});
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
}
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
}
|
|
3415
|
+
checkForUpdates().then(() => {
|
|
3416
|
+
if (process.argv.length <= 2) {
|
|
3417
|
+
interactiveMenu().catch((err) => {
|
|
3418
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
3419
|
+
process.exit(1);
|
|
3420
|
+
});
|
|
3421
|
+
} else {
|
|
3422
|
+
program.parseAsync(process.argv).catch((err) => {
|
|
3423
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
3424
|
+
process.exit(1);
|
|
3425
|
+
});
|
|
3426
|
+
}
|
|
3427
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openhome-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "CLI for managing OpenHome voice AI abilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -32,6 +32,9 @@
|
|
|
32
32
|
"commander": "^12.1.0",
|
|
33
33
|
"ws": "^8.19.0"
|
|
34
34
|
},
|
|
35
|
+
"overrides": {
|
|
36
|
+
"glob": "^11.0.0"
|
|
37
|
+
},
|
|
35
38
|
"devDependencies": {
|
|
36
39
|
"@types/archiver": "^6.0.3",
|
|
37
40
|
"@types/node": "^22.0.0",
|
package/src/cli.ts
CHANGED
|
@@ -35,6 +35,57 @@ try {
|
|
|
35
35
|
// fallback to default
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
// ── Auto-update check ────────────────────────────────────────────
|
|
39
|
+
async function checkForUpdates(): Promise<void> {
|
|
40
|
+
// Skip if explicitly disabled or already running via auto-update re-exec
|
|
41
|
+
if (process.env.OPENHOME_NO_UPDATE === "1") return;
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const res = await fetch("https://registry.npmjs.org/openhome-cli/latest", {
|
|
45
|
+
signal: AbortSignal.timeout(2000),
|
|
46
|
+
});
|
|
47
|
+
const data = (await res.json()) as { version?: string };
|
|
48
|
+
const latest = data.version;
|
|
49
|
+
if (!latest || latest === version) return;
|
|
50
|
+
|
|
51
|
+
// Only act if npm version is strictly newer
|
|
52
|
+
const toNum = (v: string) =>
|
|
53
|
+
v
|
|
54
|
+
.split(".")
|
|
55
|
+
.map(Number)
|
|
56
|
+
.reduce((a, n) => a * 1000 + n, 0);
|
|
57
|
+
if (toNum(latest) <= toNum(version)) return;
|
|
58
|
+
|
|
59
|
+
// Detect npx: argv[1] contains _npx or npm_execpath points to npx
|
|
60
|
+
const arg1 = process.argv[1] ?? "";
|
|
61
|
+
const isNpx =
|
|
62
|
+
arg1.includes("_npx") ||
|
|
63
|
+
arg1.includes(".npm/") ||
|
|
64
|
+
(process.env.npm_execpath ?? "").includes("npx");
|
|
65
|
+
|
|
66
|
+
if (isNpx) {
|
|
67
|
+
// Re-exec with latest — user gets the new version transparently
|
|
68
|
+
const { execFileSync } = await import("node:child_process");
|
|
69
|
+
execFileSync(
|
|
70
|
+
"npx",
|
|
71
|
+
[`openhome-cli@${latest}`, ...process.argv.slice(2)],
|
|
72
|
+
{ stdio: "inherit", env: { ...process.env, OPENHOME_NO_UPDATE: "1" } },
|
|
73
|
+
);
|
|
74
|
+
process.exit(0);
|
|
75
|
+
} else {
|
|
76
|
+
// Global install — show one-line notice, don't block
|
|
77
|
+
const { default: chalk } = await import("chalk");
|
|
78
|
+
console.log(
|
|
79
|
+
chalk.yellow(
|
|
80
|
+
` Update available: v${version} → v${latest} Run: npm install -g openhome-cli@latest\n`,
|
|
81
|
+
),
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
} catch {
|
|
85
|
+
// Network timeout or error — continue silently
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
38
89
|
// ── Interactive menu (bare `openhome` with no args) ──────────────
|
|
39
90
|
|
|
40
91
|
async function ensureLoggedIn(): Promise<void> {
|
|
@@ -304,14 +355,16 @@ program
|
|
|
304
355
|
|
|
305
356
|
// ── Entry point: menu if no args, subcommand otherwise ───────────
|
|
306
357
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
}
|
|
358
|
+
checkForUpdates().then(() => {
|
|
359
|
+
if (process.argv.length <= 2) {
|
|
360
|
+
interactiveMenu().catch((err: unknown) => {
|
|
361
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
362
|
+
process.exit(1);
|
|
363
|
+
});
|
|
364
|
+
} else {
|
|
365
|
+
program.parseAsync(process.argv).catch((err: unknown) => {
|
|
366
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
367
|
+
process.exit(1);
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
});
|