52efa69bf0
Use a fork of https://github.com/lstrojny/json-schema-to-zod to generate the boundary check for the config automatically.
29 lines
813 B
JavaScript
Executable file
29 lines
813 B
JavaScript
Executable file
#!/usr/bin/env node
|
||
|
||
const { parseSchema } = require('json-schema-to-zod-with-defaults')
|
||
const { schema } = require('../config.schema.json')
|
||
const { format } = require('prettier')
|
||
const { join, basename } = require('path')
|
||
const prettierConfig = require('../prettier.config')
|
||
const { writeFileSync } = require('fs')
|
||
|
||
const file = join(__dirname, '../src/generated/config_boundary.ts')
|
||
|
||
console.log(`Starting code generation for ${file}`)
|
||
|
||
const zodSchema = parseSchema(schema, true)
|
||
|
||
const code = format(
|
||
`
|
||
// Auto-generated by "${join(basename(__dirname), basename(__filename))}", don’t manually edit
|
||
|
||
import { z } from 'zod'
|
||
|
||
export const ConfigBoundary = ${zodSchema}
|
||
`,
|
||
{ filepath: 'codegen.ts', ...prettierConfig },
|
||
)
|
||
|
||
writeFileSync(file, code)
|
||
|
||
console.log(`Finished code generation for ${file}`)
|