import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { resolve } from "node:path";

const input = resolve(process.cwd(), "../../apps/api/openapi.json");
const outputDir = resolve(process.cwd(), "src");
mkdirSync(outputDir, { recursive: true });

let raw = "{}";
try {
  raw = readFileSync(input, "utf8");
} catch {
  raw = "{}";
}

writeFileSync(
  resolve(outputDir, "index.ts"),
  `export const openApiSchema = ${raw} as const;\n`,
  "utf8"
);
