#!/usr/bin/env node import { mkdir, readFile, writeFile } from "node:fs/promises"; import { dirname, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { buildOpenApiDocument } from "@projectbrain/contracts"; const root = resolve(dirname(fileURLToPath(import.meta.url)), ".."); const target = resolve(root, "docs/openapi/projectbrain-v1.json"); const generated = `${JSON.stringify(buildOpenApiDocument(), null, 2)}\n`; if (process.argv.includes("--check")) { const existing = await readFile(target, "utf8").catch(() => ""); if (existing !== generated) { console.error("OpenAPI artifact is stale. Run pnpm docs:openapi."); process.exit(1); } console.log("OpenAPI artifact matches canonical contracts."); } else { await mkdir(dirname(target), { recursive: true }); await writeFile(target, generated); console.log(`Wrote ${target}`); }