@anttiviljami/dtsgenerator
Version:
TypeScript d.ts file generator for JSON Schema file
71 lines (70 loc) • 2.66 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.clear = exports.initialize = exports.CommandOptions = exports.defaultConfigFile = void 0;
const tslib_1 = require("tslib");
const commander = tslib_1.__importStar(require("commander"));
exports.defaultConfigFile = 'dtsgen.json';
class CommandOptions {
constructor() {
this.files = [];
this.urls = [];
}
}
exports.CommandOptions = CommandOptions;
const opts = new CommandOptions();
clear();
exports.default = opts;
function initialize(argv) {
return parse(opts, argv);
}
exports.initialize = initialize;
function clear() {
opts.configFile = undefined;
opts.files = [];
opts.urls = [];
opts.stdin = undefined;
opts.out = undefined;
opts.target = undefined;
opts.info = undefined;
opts.outputAST = undefined;
}
exports.clear = clear;
function parse(options, argv) {
const program = new commander.Command();
function collectUrl(val, memo) {
memo.push(val);
return memo;
}
const pkg = require('../package.json');
program
.name(pkg.name)
.version(pkg.version)
.usage('[options] <file ... | file patterns using node-glob>')
.option('-c, --config <file>', 'set configuration file path.')
.option('--url <url>', 'input json schema from the url.', collectUrl, [])
.option('--stdin', 'read stdin with other files or urls.')
.option('-o, --out <file>', 'output filename.')
.option('-t, --target <version>', "Specify ECMAScript target version: 'ES3', 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT' (default).")
.option('--info', 'for developer mode. output loaded config and plugin details only.')
.option('--output-ast', 'output TypeScript AST instead of d.ts file.')
.addHelpText('afterAll', `
Examples:
$ dtsgen --help
$ dtsgen --out types.d.ts schema/**/*.schema.json
$ cat schema1.json | dtsgen -c dtsgen.json
$ dtsgen -o swaggerSchema.d.ts --url https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v2.0/schema.json
$ dtsgen -o petstore.d.ts --url https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/yaml/petstore.yaml
$ dtsgen -c dtsgen-test.json --info
`)
.parse(argv);
const opts = program.opts();
options.files = program.args;
options.configFile = opts.config;
options.urls = opts.url;
options.stdin = opts.stdin;
options.out = opts.out;
options.target = opts.target;
options.info = opts.info;
options.outputAST = opts.outputAst;
return program;
}
;