generate-openapi.ts 686 B

123456789101112131415161718
  1. import { fileURLToPath } from "url"
  2. const source = fileURLToPath(new URL("../../protocol/openapi.json", import.meta.url))
  3. const targets = ["../openapi.json", "../public/openapi.json"].map((path) =>
  4. fileURLToPath(new URL(path, import.meta.url)),
  5. )
  6. const document = await Bun.file(source).text()
  7. if (process.argv.includes("--check")) {
  8. const stale = (await Promise.all(targets.map((path) => Bun.file(path).text()))).some((value) => value !== document)
  9. if (stale) {
  10. console.error("Generated OpenAPI documents are stale. Run `bun run generate` from packages/www.")
  11. process.exit(1)
  12. }
  13. process.exit(0)
  14. }
  15. await Promise.all(targets.map((path) => Bun.write(path, document)))