@@ -14,25 +14,30 @@ import { generateTemplate } from './lib/generate-template';
1414import { filterTag } from './lib/filter-tag' ;
1515import { filterUrl } from './lib/filter-url' ;
1616import { readConfig } from './lib/read-config' ;
17+ import { SilentSpinner } from './silent-spinner' ;
1718
18- const sleep = ( ) => timers . setTimeout ( 300 ) ;
19+ const argv = minimist ( process . argv . slice ( 2 ) , {
20+ alias : { config : [ 'c' ] , env : [ 'e' ] } ,
21+ } ) ;
22+ const silent = Boolean ( argv [ 'silent' ] ) ;
23+ const env = argv [ 'env' ] || process . env [ 'NODE_ENV' ] || 'development' ;
24+ const configFile = argv [ 'config' ] ;
1925
26+ const sleep = ( ) => timers . setTimeout ( 300 ) ;
2027const toArray = ( value : any ) => ( Array . isArray ( value ) ? value : [ value ] ) ;
2128
22- const spinner = new Listr < {
29+ const spinner = ( silent ? new SilentSpinner ( [ ] ) : new Listr ( [ ] ) ) as Listr < {
2330 configs : OpenapiClientConfig [ ] ;
2431 docs : OpenAPIV3 . Document [ ] ;
2532 projects : Record < string , { dts : string ; js : string } > ;
26- } > ( [ ] ) ;
33+ } > ;
2734
2835spinner . add ( {
2936 title : '读取配置文件openapi.config.ts' ,
3037 task : async ( ctx , task ) => {
31- const userConfig = readConfig ( ) ;
38+ const userConfig = readConfig ( configFile ) ;
3239
3340 if ( typeof userConfig === 'function' ) {
34- const args = minimist ( process . argv . slice ( 2 ) , { alias : { env : [ 'e' ] } } ) ;
35- const env = args [ 'env' ] || process . env [ 'NODE_ENV' ] || 'development' ;
3641 task . title += ` ${ colors . gray ( env ) } ` ;
3742 ctx . configs = toArray ( await userConfig ( env ) ) ;
3843 } else {
@@ -114,4 +119,4 @@ spinner.add({
114119 } ,
115120} ) ;
116121
117- spinner . run ( ) ;
122+ await spinner . run ( ) ;
0 commit comments