periderm-cli 0.1.32 → 0.1.33
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/bin.js +14 -9
- package/dist/index.js +3 -1
- package/dist/update-notifier.js +25 -19
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { checkUpdate } from "./update-notifier.js";
|
|
3
|
+
// Kick off the update check in parallel — non-blocking
|
|
3
4
|
const updatePromise = checkUpdate();
|
|
4
|
-
process.on("uncaughtException",
|
|
5
|
+
process.on("uncaughtException", (err) => {
|
|
5
6
|
console.error(err);
|
|
6
|
-
await updatePromise;
|
|
7
7
|
process.exit(1);
|
|
8
8
|
});
|
|
9
|
-
process.on("unhandledRejection",
|
|
9
|
+
process.on("unhandledRejection", (err) => {
|
|
10
10
|
console.error(err);
|
|
11
|
-
await updatePromise;
|
|
12
11
|
process.exit(1);
|
|
13
12
|
});
|
|
13
|
+
// Import index.js. This starts executing the CLI but parseAsync() runs async
|
|
14
|
+
// inside it — we grab mainDone so we can properly sequence the banner.
|
|
15
|
+
const mod = await import("./index.js");
|
|
16
|
+
// Wait for the command to fully complete, then print update banner
|
|
14
17
|
try {
|
|
15
|
-
|
|
18
|
+
if (mod.mainDone)
|
|
19
|
+
await mod.mainDone;
|
|
20
|
+
const banner = await updatePromise;
|
|
21
|
+
if (banner)
|
|
22
|
+
console.error(banner);
|
|
16
23
|
}
|
|
17
|
-
catch
|
|
18
|
-
|
|
19
|
-
await updatePromise;
|
|
20
|
-
process.exit(1);
|
|
24
|
+
catch {
|
|
25
|
+
// silently ignore update check errors
|
|
21
26
|
}
|
package/dist/index.js
CHANGED
|
@@ -439,6 +439,8 @@ program
|
|
|
439
439
|
console.info(chalk.white("Run ") + chalk.white("$ periderm login") + chalk.white(" to re-authenticate."));
|
|
440
440
|
console.info("");
|
|
441
441
|
});
|
|
442
|
+
// Exported so bin.ts can await full command completion before printing the update banner.
|
|
443
|
+
export let mainDone = Promise.resolve();
|
|
442
444
|
if (process.argv.length === 2) {
|
|
443
445
|
console.info("");
|
|
444
446
|
console.info(chalk.hex("#FF4D00")(PERIDERM_ASCII));
|
|
@@ -449,7 +451,7 @@ if (process.argv.length === 2) {
|
|
|
449
451
|
program.help();
|
|
450
452
|
}
|
|
451
453
|
else {
|
|
452
|
-
program.parseAsync().catch(async (e) => {
|
|
454
|
+
mainDone = program.parseAsync().catch(async (e) => {
|
|
453
455
|
console.error(e);
|
|
454
456
|
const err = e instanceof Error ? e : new Error(String(e));
|
|
455
457
|
await reportCliError({
|
package/dist/update-notifier.js
CHANGED
|
@@ -5,34 +5,41 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
import { readConfig } from "./config.js";
|
|
6
6
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
7
|
const pkgPath = path.join(__dirname, "..", "package.json");
|
|
8
|
+
/**
|
|
9
|
+
* Checks for a newer version of the CLI on NPM.
|
|
10
|
+
* Returns the update banner string if an update is available, otherwise null.
|
|
11
|
+
* Kept separate from printing so the caller can await it after the main command
|
|
12
|
+
* completes (avoiding a race with process.exit).
|
|
13
|
+
*/
|
|
8
14
|
export async function checkUpdate() {
|
|
9
15
|
try {
|
|
10
16
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
11
17
|
const currentVersion = pkg.version;
|
|
12
18
|
const name = pkg.name;
|
|
13
|
-
// Timeout fetch after
|
|
19
|
+
// Timeout fetch after 3 seconds so we never hang the CLI
|
|
14
20
|
const controller = new AbortController();
|
|
15
|
-
const timeoutId = setTimeout(() => controller.abort(),
|
|
21
|
+
const timeoutId = setTimeout(() => controller.abort(), 3000);
|
|
16
22
|
const res = await fetch(`https://registry.npmjs.org/${name}/latest`, {
|
|
17
23
|
signal: controller.signal,
|
|
18
24
|
});
|
|
19
25
|
clearTimeout(timeoutId);
|
|
20
26
|
if (!res.ok)
|
|
21
|
-
return;
|
|
27
|
+
return null;
|
|
22
28
|
const data = await res.json();
|
|
23
29
|
const latestVersion = data.version;
|
|
24
|
-
if (latestVersion
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
if (!latestVersion || latestVersion === currentVersion)
|
|
31
|
+
return null;
|
|
32
|
+
const cfg = readConfig();
|
|
33
|
+
const apiUrl = cfg?.apiUrl ?? "https://periderm-cli.vercel.app";
|
|
34
|
+
const isUnix = process.platform !== "win32" && process.platform !== "android";
|
|
35
|
+
const npmCmd = isUnix ? `sudo npm install -g ${name}` : `npm install -g ${name}`;
|
|
36
|
+
const curlCmd = `curl -fsSL ${apiUrl}/install.sh | bash`;
|
|
37
|
+
const title = `A new version of Periderm CLI is available: ${currentVersion} → ${latestVersion}`;
|
|
38
|
+
const textNpm = `Update via npm: ${npmCmd}`;
|
|
39
|
+
const textCurl = `Update via curl: ${curlCmd}`;
|
|
40
|
+
const width = Math.max(title.length, textNpm.length, textCurl.length) + 4;
|
|
41
|
+
const pad = (rawLen) => " ".repeat(Math.max(0, width - rawLen - 2));
|
|
42
|
+
return `
|
|
36
43
|
╭${"─".repeat(width)}╮
|
|
37
44
|
│${" ".repeat(width)}│
|
|
38
45
|
│ A new version of Periderm CLI is available: ${chalk.dim(currentVersion)} → ${chalk.green(latestVersion)}${pad(title.length)}│
|
|
@@ -41,11 +48,10 @@ export async function checkUpdate() {
|
|
|
41
48
|
│ Update via curl: ${chalk.cyan(curlCmd)}${pad(textCurl.length)}│
|
|
42
49
|
│${" ".repeat(width)}│
|
|
43
50
|
╰${"─".repeat(width)}╯
|
|
44
|
-
|
|
45
|
-
console.log(box);
|
|
46
|
-
}
|
|
51
|
+
`;
|
|
47
52
|
}
|
|
48
|
-
catch
|
|
53
|
+
catch {
|
|
49
54
|
// Ignore any network/parsing errors silently
|
|
55
|
+
return null;
|
|
50
56
|
}
|
|
51
57
|
}
|