build.ts 955 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env bun
  2. const dir = new URL("..", import.meta.url).pathname
  3. process.chdir(dir)
  4. import { $ } from "bun"
  5. import path from "path"
  6. import { createClient } from "@hey-api/openapi-ts"
  7. await $`bun dev generate > ${dir}/openapi.json`.cwd(path.resolve(dir, "../../opencode"))
  8. await createClient({
  9. input: "./openapi.json",
  10. output: {
  11. path: "./src/v2/gen",
  12. tsConfigPath: path.join(dir, "tsconfig.json"),
  13. clean: true,
  14. },
  15. plugins: [
  16. {
  17. name: "@hey-api/typescript",
  18. exportFromIndex: false,
  19. },
  20. {
  21. name: "@hey-api/sdk",
  22. instance: "OpencodeClient",
  23. exportFromIndex: false,
  24. auth: false,
  25. paramsStructure: "flat",
  26. },
  27. {
  28. name: "@hey-api/client-fetch",
  29. exportFromIndex: false,
  30. baseUrl: "http://localhost:4096",
  31. },
  32. ],
  33. })
  34. await $`bun prettier --write src/gen`
  35. await $`bun prettier --write src/v2`
  36. await $`rm -rf dist`
  37. await $`bun tsc`
  38. await $`rm openapi.json`