-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild-json-schemas.mjs
64 lines (53 loc) · 1.31 KB
/
build-json-schemas.mjs
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
62
63
64
/**
* Helper script to create json schemas from typescript interfaces required
* by the well-known-messages.
*/
/* global console, process */
import fs from 'node:fs';
import path from 'node:path';
import TJS from 'typescript-json-schema';
const inputFiles = [
path.join('src', 'lib', 'adapter-config.d.ts'),
];
const outDir = path.join('well-known-messages', 'schemas');
const settings = {
required: true,
};
const compilerOptions = {
strictNullChecks: true,
skipLibCheck: true,
};
const program = TJS.getProgramFromFiles(
inputFiles,
compilerOptions,
'.',
);
/**
* Schemas to create
*/
const schemas = [
{
type: 'global.ioBroker.AdapterConfigMessagesLang',
file: 'messages.json',
settings,
},
{
type: 'global.ioBroker.WellKnownMessagesIndex',
file: 'index.json',
settings,
},
];
fs.mkdirSync(outDir, { recursive: true });
let retval = 0;
// loop over all given schemas and create the files
for (const s of schemas) {
const schema = TJS.generateSchema(program, s.type, s.settings);
if (!schema) {
console.error(`Cloud not create schema for type ${s.type}!`);
retval = 1;
continue;
}
fs.writeFileSync(path.join(outDir, s.file), JSON.stringify(schema, undefined, 2), { encoding: 'utf8' });
console.log(`Schema ${s.file} created.`);
}
process.exit(retval);