File tree Expand file tree Collapse file tree 2 files changed +34
-16
lines changed
Expand file tree Collapse file tree 2 files changed +34
-16
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+
3+ /**
4+ * Generates the typedefs for the JSON generator from the JSON schema
5+ *
6+ * To use, just run this.
7+ */
8+
9+ import { join } from 'node:path' ;
10+ import { readFile , writeFile } from 'node:fs/promises' ;
11+ import { parse } from 'jsonc-parser' ;
12+ import { compile } from 'json-schema-to-typescript' ;
13+
14+ const JSON_GENERATOR_PATH = join (
15+ import . meta. dirname ,
16+ '..' ,
17+ 'src' ,
18+ 'generators' ,
19+ 'json'
20+ ) ;
21+ const SCHEMA_PATH = join ( JSON_GENERATOR_PATH , 'schema.jsonc' ) ;
22+ const TYPES_PATH = join ( JSON_GENERATOR_PATH , 'generated.d.ts' ) ;
23+
24+ // Read the contents of the JSON schema
25+ const schemaString = await readFile ( SCHEMA_PATH , 'utf8' ) ;
26+
27+ // Parse the JSON schema into an object
28+ const schema = await parse ( schemaString ) ;
29+
30+ // Compile the the JSON schema into TypeScript typedefs
31+ const typeDefs = await compile ( schema , 'ApiDocSchema' ) ;
32+
33+ // Write the types to the expected output path
34+ await writeFile ( TYPES_PATH , typeDefs ) ;
You can’t perform that action at this time.
0 commit comments