Skip to content

Commit 7e301ef

Browse files
committed
WIP
1 parent 4dbc15d commit 7e301ef

7 files changed

Lines changed: 497 additions & 58 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ coverage/
33
.DS_Store
44
npm-debug.log
55
dist/
6+
tsconfig.schema.json
7+
tsconfig.schemastore-schema.json

package-lock.json

Lines changed: 214 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@
1111
"files": [
1212
"dist/",
1313
"register/",
14-
"LICENSE"
14+
"LICENSE",
15+
"tsconfig.schema.json",
16+
"tsconfig.schemastore-schema.json"
1517
],
1618
"scripts": {
1719
"lint": "tslint \"src/**/*.ts\" --project tsconfig.json",
18-
"build": "rimraf dist && tsc",
20+
"clean": "rimraf dist && rimraf tsconfig.schema.json && rimraf tsconfig.schemastore-schema.json",
21+
"build": "npm run clean && npm run build:tsc && npm run build:configSchema",
22+
"build:tsc": "tsc",
23+
"build:configSchema": "typescript-json-schema --topRef --refs --validationKeywords allOf --out tsconfig.schema.json tsconfig.json TsConfigSchema && node --require ./register ./scripts/create-merged-schema",
1924
"test-spec": "mocha dist/**/*.spec.js -R spec --bail",
2025
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- \"dist/**/*.spec.js\" -R spec --bail",
2126
"test": "npm run build && npm run lint && npm run test-cov",
@@ -55,6 +60,7 @@
5560
"@types/react": "^16.0.2",
5661
"@types/semver": "^6.0.0",
5762
"@types/source-map-support": "^0.5.0",
63+
"axios": "^0.19.0",
5864
"chai": "^4.0.1",
5965
"istanbul": "^0.4.0",
6066
"mocha": "^6.1.4",
@@ -65,7 +71,8 @@
6571
"semver": "^6.1.0",
6672
"tslint": "^5.11.0",
6773
"tslint-config-standard": "^9.0.0",
68-
"typescript": "^3.7.2"
74+
"typescript": "^3.7.2",
75+
"typescript-json-schema": "0.40.0"
6976
},
7077
"peerDependencies": {
7178
"typescript": ">=2.7"

scripts/create-merged-schema.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env ts-node
2+
/*
3+
* Create a complete JSON schema for tsconfig.json
4+
* by merging the schemastore schema with our ts-node additions.
5+
* This merged schema can be submitted in a pull request to
6+
* SchemaStore.
7+
*/
8+
9+
import axios from 'axios';
10+
import * as Path from 'path';
11+
import * as fs from 'fs';
12+
13+
async function main() {
14+
/** schemastore definition */
15+
const schemastoreSchema = (await axios.get(
16+
'https://schemastore.azurewebsites.net/schemas/json/tsconfig.json',
17+
{ responseType: "json" }
18+
)).data;
19+
20+
/** ts-node schema auto-generated from ts-node source code */
21+
const typescriptNodeSchema = require('../tsconfig.schema.json');
22+
23+
/** Patch ts-node stuff into the schemastore definition. */
24+
const mergedSchema = {
25+
...schemastoreSchema,
26+
definitions: {
27+
...schemastoreSchema.definitions,
28+
tsNodeDefinition: {
29+
properties: {
30+
'ts-node': {
31+
...typescriptNodeSchema.definitions.TsConfigOptions,
32+
description: typescriptNodeSchema.definitions.TsConfigSchema.properties['ts-node'].description,
33+
properties: {
34+
...typescriptNodeSchema.definitions.TsConfigOptions.properties,
35+
compilerOptions: {
36+
...typescriptNodeSchema.definitions.TsConfigOptions.properties.compilerOptions,
37+
allOf: [{
38+
$ref: '#/definitions/compilerOptionsDefinition/properties/compilerOptions'
39+
}]
40+
}
41+
}
42+
}
43+
}
44+
},
45+
},
46+
allOf: [
47+
...schemastoreSchema.allOf.slice(0, 4),
48+
{ "$ref": "#/definitions/tsNodeDefinition" },
49+
...schemastoreSchema.allOf.slice(4),
50+
]
51+
};
52+
fs.writeFileSync(
53+
Path.resolve(__dirname, '../tsconfig.schemastore-schema.json'),
54+
JSON.stringify(mergedSchema, null, 2)
55+
);
56+
}
57+
58+
main();

0 commit comments

Comments
 (0)