diff --git a/docs/docs.ensnode.io/package.json b/docs/docs.ensnode.io/package.json index 234056edf2..d87304d81f 100644 --- a/docs/docs.ensnode.io/package.json +++ b/docs/docs.ensnode.io/package.json @@ -13,7 +13,7 @@ "homepage": "https://github.com/namehash/ensnode/tree/main/docs/docs.ensnode.io", "scripts": { "mint": "pnpm dlx mint@^4.1.0", - "generate:openapi": "pnpm --filter ensapi exec tsx --tsconfig tsconfig.json ../../scripts/generate-ensapi-openapi.ts" + "generate:openapi": "pnpm --filter ensapi exec tsx --tsconfig tsconfig.json ../../scripts/generate-openapi.ts --out ../../docs/docs.ensnode.io/ensapi-openapi.json" }, "packageManager": "pnpm@10.28.0" } diff --git a/scripts/generate-ensapi-openapi.ts b/scripts/generate-openapi.ts similarity index 61% rename from scripts/generate-ensapi-openapi.ts rename to scripts/generate-openapi.ts index 597653e170..2619f0fab6 100644 --- a/scripts/generate-ensapi-openapi.ts +++ b/scripts/generate-openapi.ts @@ -1,9 +1,19 @@ /** - * Generates a static OpenAPI 3.1 JSON document for ENSApi. + * Generates a static OpenAPI 3.1 JSON document for an app. * - * Usage: pnpm generate:openapi + * This script is app-agnostic — it imports `generateOpenApi31Document` from + * `@/openapi-document`, which resolves to whichever app context the script + * is executed in (controlled by `--filter ` in the calling script). * - * Output: docs/docs.ensnode.io/ensapi-openapi.json + * Usage: + * pnpm --filter exec tsx --tsconfig tsconfig.json \ + * ../../scripts/generate-openapi.ts --out + * + * Example: + * pnpm --filter ensapi exec tsx --tsconfig tsconfig.json \ + * ../../scripts/generate-openapi.ts --out ../../docs/docs.ensnode.io/ensapi-openapi.json + * + * The --out path is resolved relative to the app's root directory. * * This script has no runtime dependencies — it calls generateOpenApi31Document() * which uses only stub route handlers and static metadata. @@ -12,12 +22,23 @@ import { execFileSync } from "node:child_process"; import { mkdirSync, writeFileSync } from "node:fs"; import { dirname, resolve } from "node:path"; -import { fileURLToPath } from "node:url"; +import { parseArgs } from "node:util"; import { generateOpenApi31Document } from "@/openapi-document"; -const __dirname = dirname(fileURLToPath(import.meta.url)); -const outputPath = resolve(__dirname, "..", "docs", "docs.ensnode.io", "ensapi-openapi.json"); +const { values } = parseArgs({ + options: { + out: { type: "string" }, + }, + strict: true, +}); + +if (!values.out) { + console.error("Error: --out is required."); + process.exit(1); +} + +const outputPath = resolve(values.out); // Generate the document (no additional servers for the static spec) const document = generateOpenApi31Document();