specli 0.0.14 → 0.0.15

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.
@@ -4,6 +4,7 @@ type MainOptions = {
4
4
  server?: string;
5
5
  serverVars?: string[];
6
6
  auth?: string;
7
+ version?: string;
7
8
  };
8
9
  export declare function main(argv: string[], options?: MainOptions): Promise<void>;
9
10
  export {};
package/dist/cli/main.js CHANGED
@@ -1,6 +1,24 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
1
4
  import { Command } from "commander";
2
5
  import { getArgValue, hasAnyArg } from "./runtime/argv.js";
3
6
  import { collectRepeatable } from "./runtime/collect.js";
7
+ /**
8
+ * Reads the version from package.json at runtime.
9
+ * Used when running in non-compiled mode.
10
+ */
11
+ function getPackageVersion() {
12
+ try {
13
+ const currentDir = dirname(fileURLToPath(import.meta.url));
14
+ const packageJsonPath = join(currentDir, "../../package.json");
15
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
16
+ return packageJson.version ?? "0.0.0";
17
+ }
18
+ catch {
19
+ return "0.0.0";
20
+ }
21
+ }
4
22
  import { readStdinText } from "./runtime/compat.js";
5
23
  import { buildRuntimeContext } from "./runtime/context.js";
6
24
  import { addGeneratedCommands } from "./runtime/generated.js";
@@ -10,9 +28,12 @@ import { toMinimalSchemaOutput } from "./schema.js";
10
28
  import { stableStringify } from "./stable-json.js";
11
29
  export async function main(argv, options = {}) {
12
30
  const program = new Command();
31
+ // Get version - use embedded version if available, otherwise read from package.json
32
+ const cliVersion = options.version ?? getPackageVersion();
13
33
  program
14
34
  .name(options.cliName ?? "specli")
15
35
  .description("Generate a CLI from an OpenAPI spec")
36
+ .version(cliVersion, "-v, --version", "Output the version number")
16
37
  .option("--spec <urlOrPath>", "OpenAPI URL or file path")
17
38
  .option("--server <url>", "Override server/base URL")
18
39
  .option("--server-var <name=value>", "Server URL template variable (repeatable)", collectRepeatable)
package/dist/cli.js CHANGED
@@ -1,10 +1,27 @@
1
1
  #!/usr/bin/env node
2
+ import { readFileSync } from "node:fs";
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
2
5
  import { Command } from "commander";
3
6
  function collect(value, previous = []) {
4
7
  return previous.concat([value]);
5
8
  }
9
+ function getPackageVersion() {
10
+ try {
11
+ const currentDir = dirname(fileURLToPath(import.meta.url));
12
+ const packageJsonPath = join(currentDir, "../package.json");
13
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
14
+ return packageJson.version ?? "0.0.0";
15
+ }
16
+ catch {
17
+ return "0.0.0";
18
+ }
19
+ }
6
20
  const program = new Command();
7
- program.name("specli").description("Generate CLIs from OpenAPI specs");
21
+ program
22
+ .name("specli")
23
+ .description("Generate CLIs from OpenAPI specs")
24
+ .version(getPackageVersion(), "-v, --version", "Output the version number");
8
25
  // ─────────────────────────────────────────────────────────────
9
26
  // exec command - runs spec dynamically (works in both Bun and Node.js)
10
27
  // ─────────────────────────────────────────────────────────────
package/dist/compiled.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { main } from "./cli/main.js";
3
3
  import { env, envRequired } from "./macros/env.js" with { type: "macro" };
4
4
  import { loadSpec } from "./macros/spec.js" with { type: "macro" };
5
+ import { version } from "./macros/version.js" with { type: "macro" };
5
6
  // This entrypoint is intended to be compiled.
6
7
  // All values are embedded via Bun macros at bundle-time.
7
8
  const embeddedSpecText = await loadSpec(envRequired("SPECLI_SPEC"));
@@ -9,10 +10,12 @@ const cliName = env("SPECLI_NAME");
9
10
  const server = env("SPECLI_SERVER");
10
11
  const serverVars = env("SPECLI_SERVER_VARS");
11
12
  const auth = env("SPECLI_AUTH");
13
+ const embeddedVersion = version();
12
14
  await main(process.argv, {
13
15
  embeddedSpecText,
14
16
  cliName,
15
17
  server,
16
18
  serverVars: serverVars ? serverVars.split(",") : undefined,
17
19
  auth,
20
+ version: embeddedVersion,
18
21
  });
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Bun macro: reads the version from package.json at bundle-time.
3
+ */
4
+ export declare function version(): string;
@@ -0,0 +1,9 @@
1
+ import { join } from "node:path";
2
+ /**
3
+ * Bun macro: reads the version from package.json at bundle-time.
4
+ */
5
+ export function version() {
6
+ const packageJsonPath = join(import.meta.dir, "../../package.json");
7
+ const packageJson = require(packageJsonPath);
8
+ return packageJson.version;
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "specli",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "type": "module",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -16,7 +16,8 @@
16
16
  "files": [
17
17
  "bin",
18
18
  "dist",
19
- "README.md"
19
+ "README.md",
20
+ "package.json"
20
21
  ],
21
22
  "scripts": {
22
23
  "build": "tsc",