|
| 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