-
Notifications
You must be signed in to change notification settings - Fork 17
/
schema.js
46 lines (38 loc) · 1.31 KB
/
schema.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
42
43
44
45
46
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
const childProcess = require('child_process');
const json2ts = require('json-schema-to-typescript');
const fs = require('fs');
const prettier = require('prettier');
const SCHEMA_PATH = 'src/schema.ts';
async function generateInterface(schemaPath, filepath) {
const bannerComment =
'/* eslint-disable */ \n/**\n* This file was automatically generated by json-schema-to-typescript.\n* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,\n* and run jlpm build:schema to regenerate this file.\n*/';
const prettierConfig = {
singleQuote: true,
trailingComma: 'none',
arrowParens: 'avoid'
};
const content = await json2ts.compileFromFile(schemaPath, {
unreachableDefinitions: true,
unknownAny: false,
bannerComment,
format: true,
style: {
singleQuote: true
}
});
const formatted = prettier.format(content, {
...prettierConfig,
filepath
});
return formatted;
}
function writeFile() {
const schemaPath = 'jupyter_app_launcher/schema/config.schema.json';
const schemaContent = generateInterface(schemaPath, SCHEMA_PATH);
schemaContent.then(content => fs.writeFileSync(SCHEMA_PATH, content));
}
if (require.main === module) {
writeFile();
}