Skip to content

Commit 78f73f2

Browse files
committed
tmp
1 parent 35ecdc7 commit 78f73f2

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

tmp.mjs

Lines changed: 0 additions & 16 deletions
This file was deleted.

tools/generate-json-types.mjs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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);

0 commit comments

Comments
 (0)