@@ -6,7 +6,6 @@ const path = require("path");
6
6
const meow = require ( "meow" ) ;
7
7
const glob = require ( "tiny-glob" ) ;
8
8
const { default : openapiTS } = require ( "../dist/cjs/index.js" ) ;
9
- const { loadSpec } = require ( "./loaders" ) ;
10
9
11
10
const cli = meow (
12
11
`Usage
@@ -71,20 +70,21 @@ async function generateSchema(pathToSpec) {
71
70
const output = cli . flags . output ? OUTPUT_FILE : OUTPUT_STDOUT ; // FILE or STDOUT
72
71
73
72
// load spec
74
- let spec = undefined ;
75
- try {
76
- spec = await loadSpec ( pathToSpec , {
77
- auth : cli . flags . auth ,
78
- log : output !== OUTPUT_STDOUT ,
79
- } ) ;
80
- } catch ( err ) {
81
- errorAndExit ( `❌ ${ err } `) ;
73
+ if ( ! cli . flags . output ) {
74
+ output = "STDOUT" ; // if --output not specified, fall back to stdout
75
+ }
76
+ if ( output === "FILE" ) {
77
+ console . info ( bold ( `✨ openapi-typescript ${ require ( "../package.json" ) . version } ` ) ) ; // don’t log anything to console!
78
+ }
79
+ if ( cli . flags . rawSchema && ! cli . flags . version ) {
80
+ throw new Error ( `--raw-schema requires --version flag `) ;
82
81
}
83
82
84
83
// generate schema
85
- const result = openapiTS ( spec , {
84
+ const result = await openapiTS ( pathToSpec , {
86
85
auth : cli . flags . auth ,
87
86
additionalProperties : cli . flags . additionalProperties ,
87
+ silent : output === "STDOUT" ,
88
88
immutableTypes : cli . flags . immutableTypes ,
89
89
defaultNonNullable : cli . flags . defaultNonNullable ,
90
90
prettierConfig : cli . flags . prettierConfig ,
@@ -108,6 +108,7 @@ async function generateSchema(pathToSpec) {
108
108
console . log ( green ( `🚀 ${ pathToSpec } -> ${ bold ( outputFile ) } [${ time } ms]` ) ) ;
109
109
} else {
110
110
process . stdout . write ( result ) ;
111
+ // (still) don’t log anything to console!
111
112
}
112
113
113
114
return result ;
@@ -148,7 +149,7 @@ async function main() {
148
149
errorAndExit ( `❌ Expected directory for --output if using glob patterns. Received "${ cli . flags . output } ".` ) ;
149
150
}
150
151
151
- // generate schema(s)
152
+ // generate schema(s) in parallel
152
153
await Promise . all (
153
154
inputSpecPaths . map ( async ( specPath ) => {
154
155
if ( cli . flags . output !== "." && output === OUTPUT_FILE ) {
0 commit comments