openhome-cli 0.1.6 → 0.1.8

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 CHANGED
@@ -387,11 +387,15 @@ async function setupJwt() {
387
387
  ` Mac \u2192 press ${chalk2.cyan("Cmd + Option + J")}`,
388
388
  ` Windows / Linux \u2192 press ${chalk2.cyan("F12")}, then click ${chalk2.cyan("Console")}`,
389
389
  "",
390
- `${chalk2.bold("2.")} Paste this command and press ${chalk2.bold("Enter")}:`,
390
+ `${chalk2.bold("2.")} Chrome may show a warning:`,
391
+ ` ${chalk2.yellow(`"Don't paste code you don't understand..."`)}`,
392
+ ` If so, type ${chalk2.cyan("allow pasting")} and press ${chalk2.bold("Enter")} first.`,
393
+ "",
394
+ `${chalk2.bold("3.")} Paste this command and press ${chalk2.bold("Enter")}:`,
391
395
  "",
392
396
  ` ${chalk2.green("copy(localStorage.getItem('token'))")}`,
393
397
  "",
394
- `${chalk2.bold("3.")} Your token is now copied to your clipboard.`,
398
+ `${chalk2.bold("4.")} Your token is now copied to your clipboard.`,
395
399
  ` Come back here and paste it below.`
396
400
  ].join("\n"),
397
401
  "How to get your session token"
@@ -3216,6 +3220,39 @@ try {
3216
3220
  version = pkg.version ?? version;
3217
3221
  } catch {
3218
3222
  }
3223
+ async function checkForUpdates() {
3224
+ if (process.env.OPENHOME_NO_UPDATE === "1") return;
3225
+ try {
3226
+ const res = await fetch("https://registry.npmjs.org/openhome-cli/latest", {
3227
+ signal: AbortSignal.timeout(2e3)
3228
+ });
3229
+ const data = await res.json();
3230
+ const latest = data.version;
3231
+ if (!latest || latest === version) return;
3232
+ const toNum = (v) => v.split(".").map(Number).reduce((a, n) => a * 1e3 + n, 0);
3233
+ if (toNum(latest) <= toNum(version)) return;
3234
+ const arg1 = process.argv[1] ?? "";
3235
+ const isNpx = arg1.includes("_npx") || arg1.includes(".npm/") || (process.env.npm_execpath ?? "").includes("npx");
3236
+ if (isNpx) {
3237
+ const { execFileSync } = await import("child_process");
3238
+ execFileSync(
3239
+ "npx",
3240
+ [`openhome-cli@${latest}`, ...process.argv.slice(2)],
3241
+ { stdio: "inherit", env: { ...process.env, OPENHOME_NO_UPDATE: "1" } }
3242
+ );
3243
+ process.exit(0);
3244
+ } else {
3245
+ const { default: chalk14 } = await import("chalk");
3246
+ console.log(
3247
+ chalk14.yellow(
3248
+ ` Update available: v${version} \u2192 v${latest} Run: npm install -g openhome-cli@latest
3249
+ `
3250
+ )
3251
+ );
3252
+ }
3253
+ } catch {
3254
+ }
3255
+ }
3219
3256
  async function ensureLoggedIn() {
3220
3257
  const { getApiKey: getApiKey2 } = await import("./store-USDMWKXY.js");
3221
3258
  const key = getApiKey2();
@@ -3379,14 +3416,16 @@ program.command("set-jwt [token]").description(
3379
3416
  ).action(async (token) => {
3380
3417
  await setJwtCommand(token);
3381
3418
  });
3382
- if (process.argv.length <= 2) {
3383
- interactiveMenu().catch((err) => {
3384
- console.error(err instanceof Error ? err.message : String(err));
3385
- process.exit(1);
3386
- });
3387
- } else {
3388
- program.parseAsync(process.argv).catch((err) => {
3389
- console.error(err instanceof Error ? err.message : String(err));
3390
- process.exit(1);
3391
- });
3392
- }
3419
+ checkForUpdates().then(() => {
3420
+ if (process.argv.length <= 2) {
3421
+ interactiveMenu().catch((err) => {
3422
+ console.error(err instanceof Error ? err.message : String(err));
3423
+ process.exit(1);
3424
+ });
3425
+ } else {
3426
+ program.parseAsync(process.argv).catch((err) => {
3427
+ console.error(err instanceof Error ? err.message : String(err));
3428
+ process.exit(1);
3429
+ });
3430
+ }
3431
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openhome-cli",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
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
- if (process.argv.length <= 2) {
308
- interactiveMenu().catch((err: unknown) => {
309
- console.error(err instanceof Error ? err.message : String(err));
310
- process.exit(1);
311
- });
312
- } else {
313
- program.parseAsync(process.argv).catch((err: unknown) => {
314
- console.error(err instanceof Error ? err.message : String(err));
315
- process.exit(1);
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
+ });
@@ -139,11 +139,15 @@ export async function setupJwt(): Promise<void> {
139
139
  ` Mac → press ${chalk.cyan("Cmd + Option + J")}`,
140
140
  ` Windows / Linux → press ${chalk.cyan("F12")}, then click ${chalk.cyan("Console")}`,
141
141
  "",
142
- `${chalk.bold("2.")} Paste this command and press ${chalk.bold("Enter")}:`,
142
+ `${chalk.bold("2.")} Chrome may show a warning:`,
143
+ ` ${chalk.yellow("\"Don't paste code you don't understand...\"")}`,
144
+ ` If so, type ${chalk.cyan("allow pasting")} and press ${chalk.bold("Enter")} first.`,
145
+ "",
146
+ `${chalk.bold("3.")} Paste this command and press ${chalk.bold("Enter")}:`,
143
147
  "",
144
148
  ` ${chalk.green("copy(localStorage.getItem('token'))")}`,
145
149
  "",
146
- `${chalk.bold("3.")} Your token is now copied to your clipboard.`,
150
+ `${chalk.bold("4.")} Your token is now copied to your clipboard.`,
147
151
  ` Come back here and paste it below.`,
148
152
  ].join("\n"),
149
153
  "How to get your session token",