@@ -5,7 +5,6 @@ const { bold, green, red } = require("kleur");
5
5
const path = require ( "path" ) ;
6
6
const meow = require ( "meow" ) ;
7
7
const { default : openapiTS } = require ( "../dist/cjs/index.js" ) ;
8
- const { loadSpec } = require ( "./loaders" ) ;
9
8
10
9
const cli = meow (
11
10
`Usage
@@ -58,17 +57,17 @@ async function main() {
58
57
let output = "FILE" ; // FILE or STDOUT
59
58
const pathToSpec = cli . input [ 0 ] ;
60
59
61
- // 0. setup
62
60
if ( ! cli . flags . output ) {
63
61
output = "STDOUT" ; // if --output not specified, fall back to stdout
64
62
}
65
63
if ( output === "FILE" ) {
66
- console . info ( bold ( `✨ openapi-typescript ${ require ( "../package.json" ) . version } ` ) ) ; // only log if we’re NOT writing to stdout
64
+ console . info ( bold ( `✨ openapi-typescript ${ require ( "../package.json" ) . version } ` ) ) ; // don’t log anything to console!
67
65
}
68
66
if ( cli . flags . rawSchema && ! cli . flags . version ) {
69
67
throw new Error ( `--raw-schema requires --version flag` ) ;
70
68
}
71
69
70
+ < << << << HEAD
72
71
// 1. input
73
72
let spec = undefined ;
74
73
try {
@@ -85,34 +84,31 @@ async function main() {
85
84
const result = openapiTS ( spec , {
86
85
auth : cli . flags . auth ,
87
86
additionalProperties : cli . flags . additionalProperties ,
87
+ === === =
88
+ const result = await openapiTS ( pathToSpec , {
89
+ auth : cli . flags . auth ,
90
+ silent : output === "STDOUT" ,
91
+ >>> >>> > 3 ea8d8f ( Absorb schema loading / parsing into Node API )
88
92
immutableTypes : cli . flags . immutableTypes ,
89
93
prettierConfig : cli . flags . prettierConfig ,
90
94
rawSchema : cli . flags . rawSchema ,
91
95
version : cli . flags . version ,
92
96
} ) ;
93
97
94
- // 3. output
95
98
if ( output === "FILE" ) {
96
99
// output option 1: file
97
100
const outputFile = path . resolve ( process . cwd ( ) , cli . flags . output ) ;
98
101
99
- // recursively create parent directories if they don’t exist
100
- const parentDirs = cli . flags . output . split ( path . sep ) ;
101
- for ( var i = 1 ; i < parentDirs . length ; i ++ ) {
102
- const dir = path . resolve ( process . cwd ( ) , ...parentDirs . slice ( 0 , i ) ) ;
103
- if ( ! fs . existsSync ( dir ) ) {
104
- fs . mkdirSync ( dir ) ;
105
- }
106
- }
107
-
108
- fs . writeFileSync ( outputFile , result , "utf8" ) ;
102
+ await fs . promises . mkdir ( path . dirname ( outputFile ) , { recursive : true } ) ;
103
+ await fs . promises . writeFile ( outputFile , result , "utf8" ) ;
109
104
110
105
const timeEnd = process . hrtime ( timeStart ) ;
111
106
const time = timeEnd [ 0 ] + Math . round ( timeEnd [ 1 ] / 1e6 ) ;
112
107
console . log ( green ( `🚀 ${ pathToSpec } -> ${ bold ( cli . flags . output ) } [${ time } ms]` ) ) ;
113
108
} else {
114
109
// output option 2: stdout
115
110
process . stdout . write ( result ) ;
111
+ // (still) don’t log anything to console!
116
112
}
117
113
118
114
return result ;
0 commit comments