generate-types.mts 840 B

123456789101112131415161718192021222324252627
  1. import fs from "fs/promises"
  2. import { zodToTs, createTypeAlias, printNode } from "zod-to-ts"
  3. import { $ } from "execa"
  4. import schemas from "../src/schemas"
  5. const { typeDefinitions } = schemas
  6. async function main() {
  7. const types: string[] = [
  8. "// This file is automatically generated by running `npm run generate-types`\n// Do not edit it directly.",
  9. ]
  10. for (const { schema, identifier } of typeDefinitions) {
  11. types.push(printNode(createTypeAlias(zodToTs(schema, identifier).node, identifier)))
  12. types.push(`export type { ${identifier} }`)
  13. }
  14. await fs.writeFile("src/exports/types.ts", types.join("\n\n"))
  15. await $`npx tsup src/exports/interface.ts --dts-only -d out`
  16. await fs.copyFile('out/interface.d.ts', 'src/exports/roo-code.d.ts')
  17. await $`npx prettier --write src/exports/types.ts src/exports/roo-code.d.ts`
  18. }
  19. main()