Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed Nov 29, 2019
1 parent 4dbc15d commit 7e301ef
Show file tree
Hide file tree
Showing 7 changed files with 497 additions and 58 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,5 @@ coverage/
.DS_Store
npm-debug.log
dist/
tsconfig.schema.json
tsconfig.schemastore-schema.json
214 changes: 214 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions package.json
Expand Up @@ -11,11 +11,16 @@
"files": [
"dist/",
"register/",
"LICENSE"
"LICENSE",
"tsconfig.schema.json",
"tsconfig.schemastore-schema.json"
],
"scripts": {
"lint": "tslint \"src/**/*.ts\" --project tsconfig.json",
"build": "rimraf dist && tsc",
"clean": "rimraf dist && rimraf tsconfig.schema.json && rimraf tsconfig.schemastore-schema.json",
"build": "npm run clean && npm run build:tsc && npm run build:configSchema",
"build:tsc": "tsc",
"build:configSchema": "typescript-json-schema --topRef --refs --validationKeywords allOf --out tsconfig.schema.json tsconfig.json TsConfigSchema && node --require ./register ./scripts/create-merged-schema",
"test-spec": "mocha dist/**/*.spec.js -R spec --bail",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- \"dist/**/*.spec.js\" -R spec --bail",
"test": "npm run build && npm run lint && npm run test-cov",
Expand Down Expand Up @@ -55,6 +60,7 @@
"@types/react": "^16.0.2",
"@types/semver": "^6.0.0",
"@types/source-map-support": "^0.5.0",
"axios": "^0.19.0",
"chai": "^4.0.1",
"istanbul": "^0.4.0",
"mocha": "^6.1.4",
Expand All @@ -65,7 +71,8 @@
"semver": "^6.1.0",
"tslint": "^5.11.0",
"tslint-config-standard": "^9.0.0",
"typescript": "^3.7.2"
"typescript": "^3.7.2",
"typescript-json-schema": "0.40.0"
},
"peerDependencies": {
"typescript": ">=2.7"
Expand Down
58 changes: 58 additions & 0 deletions scripts/create-merged-schema.ts
@@ -0,0 +1,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();

0 comments on commit 7e301ef

Please sign in to comment.