1 | import { exec, getDefaultArgs } from "./typescript-json-schema";
|
2 |
|
3 | export function run() {
|
4 | var helpText = "Usage: typescript-json-schema <path-to-typescript-files-or-tsconfig> <type>";
|
5 | const defaultArgs = getDefaultArgs();
|
6 |
|
7 |
|
8 | var args = require("yargs")
|
9 | .usage(helpText)
|
10 | .demand(2)
|
11 | .boolean("refs").default("refs", defaultArgs.ref)
|
12 | .describe("refs", "Create shared ref definitions.")
|
13 | .boolean("aliasRefs").default("aliasRefs", defaultArgs.aliasRef)
|
14 | .describe("aliasRefs", "Create shared ref definitions for the type aliases.")
|
15 | .boolean("topRef").default("topRef", defaultArgs.topRef)
|
16 | .describe("topRef", "Create a top-level ref definition.")
|
17 | .boolean("titles").default("titles", defaultArgs.titles)
|
18 | .describe("titles", "Creates titles in the output schema.")
|
19 | .boolean("defaultProps").default("defaultProps", defaultArgs.defaultProps)
|
20 | .describe("defaultProps", "Create default properties definitions.")
|
21 | .boolean("noExtraProps").default("noExtraProps", defaultArgs.noExtraProps)
|
22 | .describe("noExtraProps", "Disable additional properties in objects by default.")
|
23 | .boolean("propOrder").default("propOrder", defaultArgs.propOrder)
|
24 | .describe("propOrder", "Create property order definitions.")
|
25 | .boolean("useTypeOfKeyword").default("useTypeOfKeyword", defaultArgs.typeOfKeyword)
|
26 | .describe("useTypeOfKeyword", "Use typeOf keyword (https://goo.gl/DC6sni) for functions.")
|
27 | .boolean("required").default("required", defaultArgs.required)
|
28 | .describe("required", "Create required array for non-optional properties.")
|
29 | .boolean("strictNullChecks").default("strictNullChecks", defaultArgs.strictNullChecks)
|
30 | .describe("strictNullChecks", "Make values non-nullable by default.")
|
31 | .boolean("esModuleInterop").default("esModuleInterop", defaultArgs.esModuleInterop)
|
32 | .describe("esModuleInterop", "Use esModuleInterop when loading typescript modules.")
|
33 | .boolean("skipLibCheck").default("skipLibCheck", defaultArgs.skipLibCheck)
|
34 | .describe("skipLibCheck", "Use skipLibCheck when loading typescript modules.")
|
35 | .boolean("experimentalDecorators").default("experimentalDecorators", defaultArgs.experimentalDecorators)
|
36 | .describe("skipLibCheck", "Use experimentalDecorators when loading typescript modules.")
|
37 | .boolean("ignoreErrors").default("ignoreErrors", defaultArgs.ignoreErrors)
|
38 | .describe("ignoreErrors", "Generate even if the program has errors.")
|
39 | .alias("out", "o")
|
40 | .describe("out", "The output file, defaults to using stdout")
|
41 | .array("validationKeywords").default("validationKeywords", defaultArgs.validationKeywords)
|
42 | .describe("validationKeywords", "Provide additional validation keywords to include.")
|
43 | .boolean("excludePrivate").default("excludePrivate", defaultArgs.excludePrivate)
|
44 | .describe("excludePrivate", "Exclude private members from the schema.")
|
45 | .boolean("uniqueNames").default("uniqueNames", defaultArgs.uniqueNames)
|
46 | .describe("uniqueNames", "Use unique names for type symbols.")
|
47 | .array("include").default("*", defaultArgs.include)
|
48 | .describe("include", "Further limit tsconfig to include only matching files.")
|
49 | .boolean("rejectDateType").default("rejectDateType", defaultArgs.rejectDateType)
|
50 | .describe("rejectDateType", "Rejects Date fields in type definitions.")
|
51 | .string("id").default("id", defaultArgs.id)
|
52 | .describe("id", "ID of schema.")
|
53 | .option("defaultNumberType").choices("defaultNumberType", ["number", "integer"])
|
54 | .default("defaultNumberType", defaultArgs.defaultNumberType)
|
55 | .describe("defaultNumberType", "Default number type.")
|
56 | .boolean("tsNodeRegister").default("tsNodeRegister", defaultArgs.tsNodeRegister)
|
57 | .describe("tsNodeRegister", "Use ts-node/register (needed for requiring typescript files).")
|
58 | .boolean("constAsEnum").default("constAsEnum", defaultArgs.constAsEnum)
|
59 | .describe("constAsEnum", "Use enums with a single value when declaring constants. Needed for OpenAPI compatibility")
|
60 | .argv;
|
61 |
|
62 | exec(args._[0], args._[1], {
|
63 | ref: args.refs,
|
64 | aliasRef: args.aliasRefs,
|
65 | topRef: args.topRef,
|
66 | titles: args.titles,
|
67 | defaultProps: args.defaultProps,
|
68 | noExtraProps: args.noExtraProps,
|
69 | propOrder: args.propOrder,
|
70 | typeOfKeyword: args.useTypeOfKeyword,
|
71 | required: args.required,
|
72 | strictNullChecks: args.strictNullChecks,
|
73 | esModuleInterop: args.esModuleInterop,
|
74 | skipLibCheck: args.skipLibCheck,
|
75 | experimentalDecorators: args.experimentalDecorators,
|
76 | ignoreErrors: args.ignoreErrors,
|
77 | out: args.out,
|
78 | validationKeywords: args.validationKeywords,
|
79 | include: args.include,
|
80 | excludePrivate: args.excludePrivate,
|
81 | uniqueNames: args.uniqueNames,
|
82 | rejectDateType: args.rejectDateType,
|
83 | id: args.id,
|
84 | defaultNumberType: args.defaultNumberType,
|
85 | tsNodeRegister: args.tsNodeRegister,
|
86 | constAsEnum: args.constAsEnum,
|
87 | });
|
88 | }
|
89 |
|
90 | if (typeof window === "undefined" && require.main === module) {
|
91 | run();
|
92 | }
|