| 1 | import fs from "fs"; |
| 2 | import path from "path"; |
| 3 | import { fileURLToPath } from "url"; |
| 4 | import { zodToJsonSchema } from "zod-to-json-schema"; |
| 5 | import { configYamlSchema } from "../schemas/index.js"; |
| 6 | |
| 7 | // Get the directory name of the current module |
| 8 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 9 | |
| 10 | // Convert Zod schema to JSON schema |
| 11 | const jsonSchema = zodToJsonSchema(configYamlSchema, { |
| 12 | $refStrategy: "none", |
| 13 | name: "ConfigYaml", |
| 14 | }); |
| 15 | |
| 16 | // Output directory and file path |
| 17 | const outDir = path.resolve(__dirname, "../../schema"); |
| 18 | const outFile = path.join(outDir, "config-yaml-schema.json"); |
| 19 | |
| 20 | // Ensure output directory exists |
| 21 | if (!fs.existsSync(outDir)) { |
| 22 | fs.mkdirSync(outDir, { recursive: true }); |
| 23 | } |
| 24 | |
| 25 | // Write the JSON schema to file |
| 26 | fs.writeFileSync(outFile, JSON.stringify(jsonSchema, null, 2)); |
| 27 | |
| 28 | console.log(`JSON schema has been written to ${outFile}`); |