/
create-merged-schema.ts
executable file
·58 lines (53 loc) · 1.78 KB
/
create-merged-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
#!/usr/bin/env ts-node
/*
* Create a complete JSON schema for tsconfig.json
* by merging the schemastore schema with our ts-node additions.
* This merged schema can be submitted in a pull request to
* SchemaStore.
*/
import axios from 'axios';
import * as Path from 'path';
import * as fs from 'fs';
async function main() {
/** schemastore definition */
const schemastoreSchema = (await axios.get(
'https://schemastore.azurewebsites.net/schemas/json/tsconfig.json',
{ responseType: "json" }
)).data;
/** ts-node schema auto-generated from ts-node source code */
const typescriptNodeSchema = require('../tsconfig.schema.json');
/** Patch ts-node stuff into the schemastore definition. */
const mergedSchema = {
...schemastoreSchema,
definitions: {
...schemastoreSchema.definitions,
tsNodeDefinition: {
properties: {
'ts-node': {
...typescriptNodeSchema.definitions.TsConfigOptions,
description: typescriptNodeSchema.definitions.TsConfigSchema.properties['ts-node'].description,
properties: {
...typescriptNodeSchema.definitions.TsConfigOptions.properties,
compilerOptions: {
...typescriptNodeSchema.definitions.TsConfigOptions.properties.compilerOptions,
allOf: [{
$ref: '#/definitions/compilerOptionsDefinition/properties/compilerOptions'
}]
}
}
}
}
},
},
allOf: [
...schemastoreSchema.allOf.slice(0, 4),
{ "$ref": "#/definitions/tsNodeDefinition" },
...schemastoreSchema.allOf.slice(4),
]
};
fs.writeFileSync(
Path.resolve(__dirname, '../tsconfig.schemastore-schema.json'),
JSON.stringify(mergedSchema, null, 2)
);
}
main();