periderm-cli 0.1.0 → 0.1.1
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 +6 -0
- package/dist/update-notifier.js +41 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15,6 +15,8 @@ import ora from "ora";
|
|
|
15
15
|
import { PERIDERM_ASCII } from "./constants.js";
|
|
16
16
|
import { PRE_SCAN_MESSAGES, UPLOAD_MESSAGES, startRotatingMessages, finishRotatingMessages } from "./loading-messages.js";
|
|
17
17
|
import { formatScanPath } from "./scanner/progress.js";
|
|
18
|
+
import { checkUpdate } from "./update-notifier.js";
|
|
19
|
+
const updatePromise = checkUpdate();
|
|
18
20
|
const program = new Command();
|
|
19
21
|
program
|
|
20
22
|
.name("periderm")
|
|
@@ -131,6 +133,7 @@ program
|
|
|
131
133
|
}
|
|
132
134
|
}
|
|
133
135
|
}
|
|
136
|
+
await updatePromise;
|
|
134
137
|
});
|
|
135
138
|
program
|
|
136
139
|
.command("review")
|
|
@@ -190,6 +193,7 @@ program
|
|
|
190
193
|
await fs.writeFile(reportPath, JSON.stringify(scanResult, null, 2), "utf8");
|
|
191
194
|
reviewSpinner.succeed(`Deep review complete · ${findings.length} additional finding${findings.length === 1 ? "" : "s"}`);
|
|
192
195
|
console.info(chalk.white(`\nAppended to ${mdPath}\n`));
|
|
196
|
+
await updatePromise;
|
|
193
197
|
});
|
|
194
198
|
program
|
|
195
199
|
.command("watch")
|
|
@@ -353,6 +357,7 @@ program
|
|
|
353
357
|
console.info(`user: ${r.user_id}`);
|
|
354
358
|
console.info(`plan: ${r.plan}`);
|
|
355
359
|
console.info(`quota: ${r.scans_remaining} scans remaining`);
|
|
360
|
+
await updatePromise;
|
|
356
361
|
});
|
|
357
362
|
program
|
|
358
363
|
.command("logout")
|
|
@@ -367,6 +372,7 @@ program
|
|
|
367
372
|
console.info("");
|
|
368
373
|
console.info(chalk.white("Run ") + chalk.white("$ periderm login") + chalk.white(" to re-authenticate."));
|
|
369
374
|
console.info("");
|
|
375
|
+
await updatePromise;
|
|
370
376
|
});
|
|
371
377
|
program.parseAsync().catch(async (e) => {
|
|
372
378
|
console.error(e);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
const pkgPath = path.join(__dirname, "..", "package.json");
|
|
7
|
+
export async function checkUpdate() {
|
|
8
|
+
try {
|
|
9
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
10
|
+
const currentVersion = pkg.version;
|
|
11
|
+
const name = pkg.name;
|
|
12
|
+
// Timeout fetch after 1 second so we never hang the CLI
|
|
13
|
+
const controller = new AbortController();
|
|
14
|
+
const timeoutId = setTimeout(() => controller.abort(), 1000);
|
|
15
|
+
const res = await fetch(`https://registry.npmjs.org/${name}/latest`, {
|
|
16
|
+
signal: controller.signal,
|
|
17
|
+
});
|
|
18
|
+
clearTimeout(timeoutId);
|
|
19
|
+
if (!res.ok)
|
|
20
|
+
return;
|
|
21
|
+
const data = await res.json();
|
|
22
|
+
const latestVersion = data.version;
|
|
23
|
+
if (latestVersion && latestVersion !== currentVersion) {
|
|
24
|
+
// Basic semver check (only notifies if latest > current simply by string comparison or simple parsing)
|
|
25
|
+
// Since it's x.y.z, simple comparison works for basic stuff, but a strict semver check is better.
|
|
26
|
+
// We will just check if they are not equal, since latest is usually higher.
|
|
27
|
+
const box = `
|
|
28
|
+
╭──────────────────────────────────────────────────────────╮
|
|
29
|
+
│ │
|
|
30
|
+
│ A new version of Periderm CLI is available: ${chalk.dim(currentVersion)} → ${chalk.green(latestVersion)} │
|
|
31
|
+
│ Run ${chalk.cyan(`npm install -g ${name}`)} to update. │
|
|
32
|
+
│ │
|
|
33
|
+
╰──────────────────────────────────────────────────────────╯
|
|
34
|
+
`;
|
|
35
|
+
console.log(box);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
// Ignore any network/parsing errors silently
|
|
40
|
+
}
|
|
41
|
+
}
|