|
1 | 1 | /** |
2 | | - * Generates a static OpenAPI 3.1 JSON document for ENSApi. |
| 2 | + * Generates a static OpenAPI 3.1 JSON document for an app. |
3 | 3 | * |
4 | | - * Usage: pnpm generate:openapi |
| 4 | + * This script is app-agnostic — it imports `generateOpenApi31Document` from |
| 5 | + * `@/openapi-document`, which resolves to whichever app context the script |
| 6 | + * is executed in (controlled by `--filter <app>` in the calling script). |
5 | 7 | * |
6 | | - * Output: docs/docs.ensnode.io/ensapi-openapi.json |
| 8 | + * Usage: |
| 9 | + * pnpm --filter <app> exec tsx --tsconfig tsconfig.json \ |
| 10 | + * ../../scripts/generate-openapi.ts --out <output-path> |
| 11 | + * |
| 12 | + * Example: |
| 13 | + * pnpm --filter ensapi exec tsx --tsconfig tsconfig.json \ |
| 14 | + * ../../scripts/generate-openapi.ts --out ../../docs/docs.ensnode.io/ensapi-openapi.json |
| 15 | + * |
| 16 | + * The --out path is resolved relative to the app's root directory. |
7 | 17 | * |
8 | 18 | * This script has no runtime dependencies — it calls generateOpenApi31Document() |
9 | 19 | * which uses only stub route handlers and static metadata. |
|
12 | 22 | import { execFileSync } from "node:child_process"; |
13 | 23 | import { mkdirSync, writeFileSync } from "node:fs"; |
14 | 24 | import { dirname, resolve } from "node:path"; |
15 | | -import { fileURLToPath } from "node:url"; |
| 25 | +import { parseArgs } from "node:util"; |
16 | 26 |
|
17 | 27 | import { generateOpenApi31Document } from "@/openapi-document"; |
18 | 28 |
|
19 | | -const __dirname = dirname(fileURLToPath(import.meta.url)); |
20 | | -const outputPath = resolve(__dirname, "..", "docs", "docs.ensnode.io", "ensapi-openapi.json"); |
| 29 | +const { values } = parseArgs({ |
| 30 | + options: { |
| 31 | + out: { type: "string" }, |
| 32 | + }, |
| 33 | + strict: true, |
| 34 | +}); |
| 35 | + |
| 36 | +if (!values.out) { |
| 37 | + console.error("Error: --out <path> is required."); |
| 38 | + process.exit(1); |
| 39 | +} |
| 40 | + |
| 41 | +const outputPath = resolve(values.out); |
21 | 42 |
|
22 | 43 | // Generate the document (no additional servers for the static spec) |
23 | 44 | const document = generateOpenApi31Document(); |
|
0 commit comments