11import fs from "fs-extra" ;
22import { Project } from "ts-morph" ;
3- import util from "util" ;
43
54import { reader } from "./reader" ;
65import { preprocessor } from "./preprocessor" ;
@@ -10,7 +9,7 @@ import { postprocessor } from "./postprocessor";
109import { checker } from "./checker" ;
1110import { writter } from "./writter" ;
1211
13- import { ARRAY_ENTRY_STRUCTURE_PROP , DEFAULT_ENTRY_CLASS_NAME } from "./utils" ;
12+ import { normalizeOptions } from "./utils" ;
1413import type { Options } from "./utils" ;
1514
1615/**
@@ -22,81 +21,39 @@ import type { Options } from "./utils";
2221export default async function handler ( options : Options ) : Promise < void > {
2322 const content = await reader ( options . reader ) ;
2423
25- const { preserveObjectOnlyInArray = true , customPreprocessor = undefined } =
26- options ?. preprocessor ?? { } ;
27-
28- const {
29- forceNonNullable = true ,
30- forceReturnType = false ,
31- arrayEntryProp = ARRAY_ENTRY_STRUCTURE_PROP ,
32- forceNonNullableListItem = false ,
33- } = options . parser ?? { } ;
34-
35- const {
36- prefix = false ,
37- publicProps = [ ] ,
38- readonlyProps = [ ] ,
39- suffix = false ,
40- entryClassName = DEFAULT_ENTRY_CLASS_NAME ,
41- sort = true ,
42- } = options . generator ?? { } ;
43-
44- const { customPostprocessor = undefined } = options . postprocessor ?? { } ;
45-
46- const {
47- disable : disableChecker = true ,
48- keep = false ,
49- execaOptions = { } ,
50- executeOptions = { } ,
51- buildSchemaOptions = { } ,
52- } = options . checker ?? { } ;
53-
5424 const {
55- format = true ,
56- override,
57- formatOptions,
58- outputPath,
59- } = options . writter ?? { } ;
25+ normalizedPreprocessorOptions,
26+ normalizedParserOptions,
27+ normalizedGeneratorOptions,
28+ normalizedPostprocessorOptions,
29+ normalizedCheckerOptions,
30+ normalizedWritterOptions,
31+ } = normalizeOptions ( options ) ;
6032
6133 const originInput = content ;
6234
63- const preprocessed = preprocessor ( originInput , {
64- preserveObjectOnlyInArray,
65- customPreprocessor,
66- } ) ;
35+ const preprocessed = preprocessor ( originInput , normalizedPreprocessorOptions ) ;
6736
68- const parsedInfo = parser ( preprocessed , {
69- forceNonNullable,
70- forceReturnType,
71- arrayEntryProp,
72- forceNonNullableListItem,
73- } ) ;
37+ const parsedInfo = parser ( preprocessed , normalizedParserOptions ) ;
7438
75- fs . ensureFileSync ( outputPath ) ;
39+ fs . ensureFileSync ( normalizedWritterOptions . outputPath ) ;
7640
77- const source = new Project ( ) . addSourceFileAtPath ( outputPath ) ;
41+ const source = new Project ( ) . addSourceFileAtPath (
42+ normalizedWritterOptions . outputPath
43+ ) ;
7844
79- generator ( source , parsedInfo , {
80- prefix,
81- publicProps,
82- readonlyProps,
83- entryClassName,
84- suffix,
85- sort,
86- } ) ;
45+ generator ( source , parsedInfo , normalizedGeneratorOptions ) ;
8746
88- postprocessor ( source , {
89- customPostprocessor,
90- // removeUnusedDecorators,
91- } ) ;
47+ postprocessor ( source , normalizedPostprocessorOptions ) ;
9248
93- await checker ( outputPath , {
94- disable : sort || disableChecker ,
95- keep,
96- execaOptions,
97- executeOptions,
98- buildSchemaOptions,
99- } ) ;
100-
101- writter ( { outputPath, format, formatOptions, override } ) ;
49+ await checker ( normalizedWritterOptions . outputPath , normalizedCheckerOptions ) ;
50+ writter ( normalizedWritterOptions ) ;
10251}
52+
53+ export * from "./reader" ;
54+ export * from "./preprocessor" ;
55+ export * from "./parser" ;
56+ export * from "./generator" ;
57+ export * from "./postprocessor" ;
58+ export * from "./checker" ;
59+ export * from "./writter" ;
0 commit comments