Read config files and generate json schema files
- Node.js ≥ 13.6.0
- Package Manager: pnpm
- Git
pnpm run buildpnpm run cleanpnpm testpnpm run test:no-coveragepnpm test -- --onlyChangedpnpm test -- -uThis starts a Node.js REPL where you can import every module inside packages/ folder.
pnpm run replThis program requires Node.js to run.
npm install --global @ts-schema-autogen/cliThe program will scan through directory tree from working directory and search for config files whose names end with .schema.autogen.{json,yaml} to perform actions.
A config file is a JSON or YAML file that satisfies the Config type or config.schema.json JSON schema.
Config files whose names end with either .schema.autogen.json or .schema.autogen.yaml will be scanned by ts-schema-autogen, others will be skipped.
A config file can inherit compilerOptions and schemaSettings from other config files via extends property.
If your editor support IntelliSense for JSON schemas (such as Visual Studio Code), it is recommended that you have $schema property set to https://raw.githubusercontent.com/ksxnodeapps/ts-schema-autogen/master/packages/schemas/config.schema.json. Alternatively, you can use npm to install @ts-schema-autogen/schemas and set $schema property to ./node_modules/@ts-schema-autogen/schemas/config.schema.json.
input.ts
export interface MyType {
foo: 123
bar: 456
}.schema.autogen.json
{
"$schema": "https://raw.githubusercontent.com/ksxnodeapps/ts-schema-autogen/master/packages/schemas/config.schema.json",
"instruction": {
"compilerOptions": {
"strictNullChecks": true,
"strict": true,
"target": "ES2018",
"noEmit": true,
"lib": ["ESNext"]
},
"schemaSettings": {
"required": true
},
"input": "input.ts",
"symbol": "MyType",
"output": "output.json"
}
}foo.ts
/// <reference path="./bar.ts" />
export interface Foo {
readonly bar?: Bar
}bar.ts
/// <reference path="./foo.ts" />
export interface Bar {
readonly foo?: Foo
}.schema.autogen.json
{
"$schema": "https://raw.githubusercontent.com/ksxnodeapps/ts-schema-autogen/master/packages/schemas/config.schema.json",
"instruction": {
"compilerOptions": {
"strictNullChecks": true,
"strict": true,
"target": "ES2018",
"noEmit": true,
"lib": ["ESNext"]
},
"schemaSettings": {
"required": true
},
"input": [
"foo.ts",
"bar.ts"
],
"list": [
{
"symbol": "Foo",
"output": "foo.schema.json"
},
{
"symbol": "Bar",
"output": "bar.schema.json"
}
]
}
}If you have multiple config files, you may want to use extends to inherit compilerOptions and schemaSettings from a common source
settings.json
{
"$schema": "https://raw.githubusercontent.com/ksxnodeapps/ts-schema-autogen/master/packages/schemas/config.schema.json",
"instruction": {
"compilerOptions": {
"strictNullChecks": true,
"strict": true,
"target": "ES2018",
"noEmit": true,
"lib": ["ESNext"]
},
"schemaSettings": {
"required": true
}
}
}foo.schema.autogen.json
{
"$schema": "https://raw.githubusercontent.com/ksxnodeapps/ts-schema-autogen/master/packages/schemas/config.schema.json",
"extends": "settings.json",
"instruction": {
"input": "foo.ts",
"symbol": "Foo",
"output": "foo.schema.json"
}
}bar.schema.autogen.json
{
"$schema": "https://raw.githubusercontent.com/ksxnodeapps/ts-schema-autogen/master/packages/schemas/config.schema.json",
"extends": "settings.json",
"instruction": {
"input": "bar.ts",
"symbol": "Bar",
"output": "bar.schema.json"
}
}ts-schema-autogen <command>
Commands:
ts-schema-autogen test Check for out-of-date schema files
ts-schema-autogen generate Generate schema files
ts-schema-autogen clean Delete generated schema files
Options:
--version Show version number [boolean]
--pattern Regular expression that matches basename of config files
[string] [default: "\.schema\.autogen(\.(json|yaml|yml))?$"]
--ignored Name of directories to be ignored
[array] [default: [".git","node_modules"]]
--help Show help [boolean]