createIndex.ts 743 B

1234567891011121314151617181920212223242526272829303132
  1. import { readdirSync, writeFileSync, statSync } from "fs";
  2. const ignore = ["src/index.ts"];
  3. function checkSrcDir(path: string): string[] {
  4. const lines: string[] = [];
  5. for (const item of readdirSync(path)) {
  6. const itemPath = path + "/" + item;
  7. if (ignore.includes(itemPath)) {
  8. continue;
  9. }
  10. if (statSync(itemPath).isDirectory()) {
  11. lines.push(...checkSrcDir(itemPath));
  12. } else if (item.endsWith(".ts")) {
  13. lines.push('export * from "./' + itemPath.slice(4, -2) + 'js"');
  14. }
  15. }
  16. return lines;
  17. }
  18. const lines = checkSrcDir("src");
  19. lines.push(
  20. 'import { zodToJsonSchema } from "./zodToJsonSchema.js"',
  21. "export default zodToJsonSchema;",
  22. );
  23. writeFileSync("./src/index.ts", lines.join(";\n"));