lazy-skill 0.1.3 → 0.2.0
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/index.js +19 -3
- package/dist/lib/version-check.js +47 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8,7 +8,8 @@ import { skillsCommand } from "./commands/skills.js";
|
|
|
8
8
|
import { installCommand } from "./commands/install.js";
|
|
9
9
|
import { themeCommand } from "./commands/theme.js";
|
|
10
10
|
import { listenCommand } from "./commands/listen.js";
|
|
11
|
-
|
|
11
|
+
import { warnIfOutdated } from "./lib/version-check.js";
|
|
12
|
+
const VERSION = "0.2.0";
|
|
12
13
|
function help() {
|
|
13
14
|
const theme = THEMES[readConfig().theme];
|
|
14
15
|
const cmd = (name) => rgb(theme.accent, name.padEnd(26));
|
|
@@ -16,7 +17,8 @@ function help() {
|
|
|
16
17
|
${style.bold("LAZY")} ${rgb(theme.accent, style.bold("SKILL"))}${rgb(theme.support, " Zz")} ${style.gray("See it. Search it. Install it.")}
|
|
17
18
|
|
|
18
19
|
${style.bold("Usage")}
|
|
19
|
-
${cmd("lazy-skill
|
|
20
|
+
${cmd("lazy-skill")}Connect, or listen if already paired
|
|
21
|
+
${cmd("lazy-skill connect")}Pair again, then wait for installs
|
|
20
22
|
${cmd("lazy-skill listen")}Wait for installs sent from your phone
|
|
21
23
|
${cmd("lazy-skill status")}Show connection and detected tools
|
|
22
24
|
${cmd("lazy-skill skills")}List skills installed on this computer
|
|
@@ -46,11 +48,25 @@ async function main() {
|
|
|
46
48
|
console.log(VERSION);
|
|
47
49
|
return 0;
|
|
48
50
|
}
|
|
49
|
-
if (
|
|
51
|
+
if (flags.has("-h") || flags.has("--help") || command === "help") {
|
|
50
52
|
help();
|
|
51
53
|
return 0;
|
|
52
54
|
}
|
|
53
55
|
const verbose = flags.has("-v") || flags.has("--verbose");
|
|
56
|
+
// Bare `npx lazy-skill` does the thing rather than printing a menu. The
|
|
57
|
+
// product is one command, a QR, and you are done — making people discover a
|
|
58
|
+
// subcommand first is the friction it exists to remove. An already-paired
|
|
59
|
+
// computer skips straight to listening instead of pairing again.
|
|
60
|
+
// Only for the long-running commands: a stale copy matters most when the
|
|
61
|
+
// user is about to sit and wait for something that will never work.
|
|
62
|
+
const longRunning = !command || command === "connect" || command === "listen";
|
|
63
|
+
if (longRunning)
|
|
64
|
+
await warnIfOutdated(VERSION, THEMES[readConfig().theme]);
|
|
65
|
+
if (!command) {
|
|
66
|
+
if (readConfig().deviceToken)
|
|
67
|
+
return listenCommand({ once: flags.has("--once") });
|
|
68
|
+
return connectCommand({ verbose, listen: !flags.has("--no-listen") });
|
|
69
|
+
}
|
|
54
70
|
switch (command) {
|
|
55
71
|
case "connect":
|
|
56
72
|
return connectCommand({
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { style, rgb } from "../ui/theme.js";
|
|
2
|
+
/**
|
|
3
|
+
* Warns when the running copy is behind the published one.
|
|
4
|
+
*
|
|
5
|
+
* npx caches by package name, so `npx lazy-skill` happily keeps running a
|
|
6
|
+
* version it fetched days ago. That turns a fixed bug into a mystery: the
|
|
7
|
+
* user hits something already solved and has no way to know. Telling them
|
|
8
|
+
* plainly costs one request and saves the whole debugging detour.
|
|
9
|
+
*
|
|
10
|
+
* Best-effort by design — never blocks startup, never fails the command.
|
|
11
|
+
*/
|
|
12
|
+
const REGISTRY = "https://registry.npmjs.org/lazy-skill/latest";
|
|
13
|
+
const TIMEOUT_MS = 2500;
|
|
14
|
+
function isOlder(current, latest) {
|
|
15
|
+
const parse = (v) => v.split(".").map((n) => Number.parseInt(n, 10) || 0);
|
|
16
|
+
const [a, b] = [parse(current), parse(latest)];
|
|
17
|
+
for (let i = 0; i < 3; i++) {
|
|
18
|
+
if ((a[i] ?? 0) < (b[i] ?? 0))
|
|
19
|
+
return true;
|
|
20
|
+
if ((a[i] ?? 0) > (b[i] ?? 0))
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
export async function warnIfOutdated(current, theme) {
|
|
26
|
+
try {
|
|
27
|
+
const controller = new AbortController();
|
|
28
|
+
const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
|
29
|
+
const res = await fetch(REGISTRY, {
|
|
30
|
+
signal: controller.signal,
|
|
31
|
+
headers: { Accept: "application/vnd.npm.install-v1+json" },
|
|
32
|
+
});
|
|
33
|
+
clearTimeout(timer);
|
|
34
|
+
if (!res.ok)
|
|
35
|
+
return;
|
|
36
|
+
const { version } = (await res.json());
|
|
37
|
+
if (!version || !isOlder(current, version))
|
|
38
|
+
return;
|
|
39
|
+
console.log(` ${style.yellow("!")} You are running ${current}; ${style.bold(version)} is out.`);
|
|
40
|
+
console.log(` ${style.gray("npx caches, so run")} ${rgb(theme.accent, `npx lazy-skill@${version}`)} ${style.gray("to update.")}`);
|
|
41
|
+
console.log();
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// Offline, slow, or the registry is down. None of that should stop a
|
|
45
|
+
// pairing that would otherwise work.
|
|
46
|
+
}
|
|
47
|
+
}
|