generate.ts 526 B

123456789101112131415161718
  1. import { Server } from "../../server/server"
  2. import fs from "fs/promises"
  3. import path from "path"
  4. import type { CommandModule } from "yargs"
  5. export const GenerateCommand = {
  6. command: "generate",
  7. handler: async () => {
  8. const specs = await Server.openapi()
  9. const dir = "gen"
  10. await fs.rmdir(dir, { recursive: true }).catch(() => {})
  11. await fs.mkdir(dir, { recursive: true })
  12. await Bun.write(
  13. path.join(dir, "openapi.json"),
  14. JSON.stringify(specs, null, 2),
  15. )
  16. },
  17. } satisfies CommandModule