@clawcard/cli 1.0.3 → 1.0.4
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/package.json +1 -1
- package/src/commands/help.js +1 -0
- package/src/index.js +32 -2
- package/src/splash.js +23 -1
package/package.json
CHANGED
package/src/commands/help.js
CHANGED
package/src/index.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
2
|
import * as p from "@clack/prompts";
|
|
3
|
-
import
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { showSplash, checkForUpdate, VERSION } from "./splash.js";
|
|
4
5
|
import { isLoggedIn } from "./config.js";
|
|
5
6
|
|
|
7
|
+
const orange = chalk.hex("#FF6B35");
|
|
8
|
+
|
|
6
9
|
// Show splash on every invocation
|
|
7
10
|
showSplash();
|
|
8
11
|
|
|
12
|
+
// Check for updates in background (non-blocking)
|
|
13
|
+
const updatePromise = checkForUpdate();
|
|
14
|
+
|
|
9
15
|
const program = new Command();
|
|
10
|
-
program.name("clawcard").description("The ClawCard CLI").version(
|
|
16
|
+
program.name("clawcard").description("The ClawCard CLI").version(VERSION);
|
|
11
17
|
|
|
12
18
|
// Auth commands
|
|
13
19
|
program
|
|
@@ -142,6 +148,22 @@ program
|
|
|
142
148
|
await referralCommand();
|
|
143
149
|
});
|
|
144
150
|
|
|
151
|
+
// Update
|
|
152
|
+
program
|
|
153
|
+
.command("update")
|
|
154
|
+
.description("Update to the latest version")
|
|
155
|
+
.action(async () => {
|
|
156
|
+
const s = p.spinner();
|
|
157
|
+
s.start("Checking for updates...");
|
|
158
|
+
const latest = await checkForUpdate();
|
|
159
|
+
if (latest) {
|
|
160
|
+
s.stop(`Update available: ${chalk.dim(VERSION)} → ${orange.bold(latest)}`);
|
|
161
|
+
p.log.info(`Run: ${orange("npm i -g @clawcard/cli@latest")}`);
|
|
162
|
+
} else {
|
|
163
|
+
s.stop("You're on the latest version!");
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
145
167
|
// Help
|
|
146
168
|
program
|
|
147
169
|
.command("help")
|
|
@@ -155,6 +177,14 @@ program
|
|
|
155
177
|
if (process.argv.length <= 2) {
|
|
156
178
|
const loggedIn = isLoggedIn();
|
|
157
179
|
|
|
180
|
+
// Show update notice if available (non-blocking, already fetched)
|
|
181
|
+
const latest = await updatePromise;
|
|
182
|
+
if (latest) {
|
|
183
|
+
p.log.warn(
|
|
184
|
+
`Update available: ${chalk.dim(VERSION)} → ${orange.bold(latest)} Run ${orange("npm i -g @clawcard/cli@latest")}`
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
158
188
|
const options = loggedIn
|
|
159
189
|
? [
|
|
160
190
|
{
|
package/src/splash.js
CHANGED
|
@@ -1,11 +1,33 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import { join, dirname } from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
2
5
|
|
|
3
6
|
const o = chalk.hex("#FF6B35");
|
|
4
7
|
const d = chalk.dim;
|
|
5
8
|
|
|
9
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
const pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8"));
|
|
11
|
+
export const VERSION = pkg.version;
|
|
12
|
+
|
|
13
|
+
export async function checkForUpdate() {
|
|
14
|
+
try {
|
|
15
|
+
const res = await fetch("https://registry.npmjs.org/@clawcard/cli/latest", {
|
|
16
|
+
signal: AbortSignal.timeout(3000),
|
|
17
|
+
});
|
|
18
|
+
const data = await res.json();
|
|
19
|
+
if (data.version && data.version !== VERSION) {
|
|
20
|
+
return data.version;
|
|
21
|
+
}
|
|
22
|
+
} catch {
|
|
23
|
+
// offline or timeout — skip silently
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
6
28
|
export function showSplash() {
|
|
7
29
|
console.log();
|
|
8
|
-
console.log(` 🦞 ${o.bold("clawcard.sh")}`);
|
|
30
|
+
console.log(` 🦞 ${o.bold("clawcard.sh")} ${d("v" + VERSION)}`);
|
|
9
31
|
console.log(` ${o("on-demand credit cards, email and phone for your agents")}`);
|
|
10
32
|
console.log();
|
|
11
33
|
}
|