-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathbuild-content-schema.ts
61 lines (49 loc) · 1.3 KB
/
build-content-schema.ts
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const { resolve } = require('path')
const { writeFile, mkdirSync, existsSync } = require('fs')
const { promisify } = require('util')
const TJS = require('typescript-json-schema')
const settings = {
required: true,
}
console.log('Creating TS program...')
const program = TJS.programFromConfig(resolve(__dirname, '../tsconfig.json'))
console.log('Done.')
const schemasWanted = [
'manifest',
'manufacturers',
'environments',
'core_bonus',
'frames',
'weapons',
'systems',
'mods',
'pilot_gear',
'reserves',
'talents',
'sitreps',
'skills',
'statuses',
'tags',
'npc_classes',
'npc_features',
'npc_templates',
]
console.log('Generating schemas...')
const schemaMap = schemasWanted.reduce(function (map, schemaName) {
map[schemaName] = TJS.generateSchema(program, `SCHEMA__${schemaName}`, settings)
return map
}, {})
console.log('Done.')
console.log('Emitting schemas...')
const outputDirPath = resolve(__dirname, '../schema_out')
if (!existsSync(outputDirPath)) {
mkdirSync(outputDirPath)
}
const writeFilePromise = promisify(writeFile)
const promises = Object.entries(schemaMap).map(([name, schema]) => {
return writeFilePromise(
resolve(outputDirPath, `${name}.schema.json`),
JSON.stringify(schema, null, 2)
)
})
Promise.all(promises).then(() => console.log('Done.'))