-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3_writer_library.js
executable file
·41 lines (32 loc) · 1.02 KB
/
3_writer_library.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env -S node --no-warnings
import path from "path";
import { fileURLToPath } from "url";
import CodeBlockWriter from "code-block-writer";
import data from "../data/input.json" assert { type: "json" };
main();
function main() {
const writer = new CodeBlockWriter({
newLine: "\n",
indentNumberOfSpaces: 2,
useTabs: false,
useSingleQuote: true,
});
data.forEach((val) => {
writer.write(`interface SomeInterface${val.name}`).block(() => {
writer.writeLine(`discriminator: "${val.name}";`);
writer.writeLine(`type: ${val.type};`);
});
writer.blankLine();
});
writer.writeLine(
`export type SomeInterface = ${data
.map((val) => `SomeInterface${val.name}`)
.join(" | ")};`,
);
const result = writer.toString();
const scriptFile = fileURLToPath(import.meta.url);
const projectDir = path.join(scriptFile, "..", "..");
const scriptFileRel = path.relative(projectDir, scriptFile);
console.log(`/* autogenerated by ${scriptFileRel} */`);
console.log(result);
}