sysprom 1.13.0 → 1.13.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.
@@ -1,6 +1,31 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { dirname, resolve } from "node:path";
3
+ import { fileURLToPath } from "node:url";
1
4
  import { Command } from "commander";
2
- import packageJson from "../../package.json" with { type: "json" };
3
5
  import { buildCommander } from "./define-command.js";
6
+ let cachedVersion;
7
+ function getVersion() {
8
+ if (cachedVersion === undefined) {
9
+ const __dirname = dirname(fileURLToPath(import.meta.url));
10
+ // Works from both src/cli/ (../../) and dist/src/cli/ (../../../)
11
+ const candidates = [
12
+ resolve(__dirname, "../../package.json"),
13
+ resolve(__dirname, "../../../package.json"),
14
+ ];
15
+ const pkgPath = candidates.find((p) => existsSync(p) && !p.includes("/dist/"));
16
+ if (!pkgPath)
17
+ throw new Error("Could not find sysprom package.json");
18
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
19
+ if (typeof pkg !== "object" ||
20
+ pkg === null ||
21
+ !("version" in pkg) ||
22
+ typeof pkg.version !== "string") {
23
+ throw new Error("Invalid package.json: missing version field");
24
+ }
25
+ cachedVersion = pkg.version;
26
+ }
27
+ return cachedVersion;
28
+ }
4
29
  import { validateCommand } from "./commands/validate.js";
5
30
  import { statsCommand } from "./commands/stats.js";
6
31
  import { json2mdCommand } from "./commands/json2md.js";
@@ -22,7 +47,11 @@ export const program = new Command();
22
47
  program
23
48
  .name("sysprom")
24
49
  .description("System Provenance Model CLI — record where every part of a system came from")
25
- .version(packageJson.version)
50
+ .option("-V, --version", "output the version number")
51
+ .on("option:version", () => {
52
+ console.log(getVersion());
53
+ process.exit(0);
54
+ })
26
55
  .showHelpAfterError(true);
27
56
  export const commands = [
28
57
  validateCommand,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sysprom",
3
- "version": "1.13.0",
3
+ "version": "1.13.1",
4
4
  "description": "SysProM — System Provenance Model CLI and library",
5
5
  "author": "ExaDev",
6
6
  "homepage": "https://exadev.github.io/SysProM",