-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
44 lines (36 loc) · 1.18 KB
/
cli.js
File metadata and controls
44 lines (36 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import pc from "picocolors";
import { isVerified } from "./dist/index.mjs";
const [pkgName, pkgVersion = "latest"] = process.argv.slice(2);
// 1. Help Menu
if (!pkgName || pkgName === "--help" || pkgName === "-h") {
console.log(`
${pc.bold(pc.cyan("is-verified-pkg"))} ${pc.dim("v1.0.0")}
Check if an npm package was published via OIDC provenance.
${pc.bold("Usage:")}
npx is-verified-pkg <name> [version]
`);
process.exit(0);
}
// 2. Execution logic
async function main() {
process.stdout.write(` ${pc.dim("Checking")} ${pc.bold(pkgName)}... `);
try {
const verified = await isVerified(pkgName, pkgVersion);
// Clear the "Checking..." line
process.stdout.clearLine(0);
process.stdout.cursorTo(0);
if (verified) {
console.log(` ${pc.green("√")} ${pc.bold(pkgName)} is ${pc.green("verified")}`);
process.exit(0);
} else {
console.log(` ${pc.red("×")} ${pc.bold(pkgName)} has ${pc.red("no provenance")}`);
process.exit(1);
}
} catch (err) {
process.stdout.clearLine(0);
process.stdout.cursorTo(0);
console.error(` ${pc.red("×")} ${pc.yellow("Error:")} ${err.message}`);
process.exit(1);
}
}
main();