1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const commander = require("commander");
|
4 | const fs_1 = require("fs");
|
5 | const stringify = require("json-stable-stringify");
|
6 | const generator_1 = require("./factory/generator");
|
7 | const Config_1 = require("./src/Config");
|
8 | const BaseError_1 = require("./src/Error/BaseError");
|
9 | const formatError_1 = require("./src/Utils/formatError");
|
10 | const args = commander
|
11 | .option("-p, --path <path>", "Source file path")
|
12 | .option("-t, --type <name>", "Type name")
|
13 | .option("-f, --tsconfig <path>", "Custom tsconfig.json path")
|
14 | .option("-e, --expose <expose>", "Type exposing", /^(all|none|export)$/, "export")
|
15 | .option("-j, --jsDoc <extended>", "Read JsDoc annotations", /^(none|basic|extended)$/, "extended")
|
16 | .option("--unstable", "Do not sort properties")
|
17 | .option("--strict-tuples", "Do not allow additional items on tuples")
|
18 | .option("--no-top-ref", "Do not create a top-level $ref definition")
|
19 | .option("--no-type-check", "Skip type checks to improve performance")
|
20 | .option("--no-ref-encode", "Do not encode references")
|
21 | .option("-o, --out <file>", "Set the output file (default: stdout)")
|
22 | .option("--validationKeywords [value]", "Provide additional validation keywords to include", (value, list) => list.concat(value), [])
|
23 | .option("--additional-properties", "Allow additional properties for objects with no index signature (default: false)", false)
|
24 | .parse(process.argv);
|
25 | const config = Object.assign(Object.assign({}, Config_1.DEFAULT_CONFIG), { path: args.path, tsconfig: args.tsconfig, type: args.type, expose: args.expose, topRef: args.topRef, jsDoc: args.jsDoc, sortProps: !args.unstable, strictTuples: args.strictTuples, skipTypeCheck: !args.typeCheck, encodeRefs: args.refEncode, extraTags: args.validationKeywords, additionalProperties: args.additionalProperties });
|
26 | try {
|
27 | const schema = generator_1.createGenerator(config).createSchema(args.type);
|
28 | const schemaString = config.sortProps ? stringify(schema, { space: 2 }) : JSON.stringify(schema, null, 2);
|
29 | if (args.out) {
|
30 | fs_1.writeFile(args.out, schemaString, (err) => {
|
31 | if (err)
|
32 | throw err;
|
33 | });
|
34 | }
|
35 | else {
|
36 | process.stdout.write(schemaString);
|
37 | }
|
38 | }
|
39 | catch (error) {
|
40 | if (error instanceof BaseError_1.BaseError) {
|
41 | process.stderr.write(formatError_1.formatError(error));
|
42 | process.exit(1);
|
43 | }
|
44 | else {
|
45 | throw error;
|
46 | }
|
47 | }
|
48 |
|
\ | No newline at end of file |