@@ -5,10 +5,7 @@ import { URL } from "node:url";
5
5
import glob from "fast-glob" ;
6
6
import parser from "yargs-parser" ;
7
7
import openapiTS from "../dist/index.js" ;
8
-
9
- const GREEN = "\u001b[32m" ;
10
- const BOLD = "\u001b[1m" ;
11
- const RESET = "\u001b[0m" ;
8
+ import { c , error } from "../dist/utils.js" ;
12
9
13
10
const HELP = `Usage
14
11
$ openapi-typescript [input] [options]
@@ -38,11 +35,6 @@ const HTTP_RE = /^https?:\/\//;
38
35
39
36
const timeStart = process . hrtime ( ) ;
40
37
41
- function errorAndExit ( errorMessage ) {
42
- process . exitCode = 1 ; // needed for async functions
43
- throw new Error ( errorMessage ) ;
44
- }
45
-
46
38
const [ , , ...args ] = process . argv ;
47
39
if ( args . includes ( "-ap" ) ) errorAndExit ( `The -ap alias has been deprecated. Use "--additional-properties" instead.` ) ;
48
40
if ( args . includes ( "-it" ) ) errorAndExit ( `The -it alias has been deprecated. Use "--immutable-types" instead.` ) ;
@@ -123,7 +115,7 @@ async function generateSchema(pathToSpec) {
123
115
124
116
const timeEnd = process . hrtime ( timeStart ) ;
125
117
const time = timeEnd [ 0 ] + Math . round ( timeEnd [ 1 ] / 1e6 ) ;
126
- console . log ( `🚀 ${ GREEN } ${ pathToSpec } -> ${ BOLD } ${ outputFilePath } ${ RESET } ${ GREEN } [${ time } ms]${ RESET } ` ) ;
118
+ console . log ( `🚀 ${ c . green ( ` ${ pathToSpec } → ${ c . bold ( outputFilePath ) } ` ) } ${ c . dim ( ` [${ time } ms]` ) } ` ) ;
127
119
} else {
128
120
process . stdout . write ( result ) ;
129
121
// if stdout, (still) don’t log anything to console!
@@ -147,9 +139,7 @@ async function main() {
147
139
let outputFile = new URL ( flags . output , CWD ) ;
148
140
let outputDir = new URL ( "." , outputFile ) ;
149
141
150
- if ( output === OUTPUT_FILE ) {
151
- console . info ( `✨ ${ BOLD } openapi-typescript ${ packageJSON . version } ${ RESET } ` ) ; // only log if we’re NOT writing to stdout
152
- }
142
+ if ( output === OUTPUT_FILE ) console . info ( `✨ ${ c . bold ( `openapi-typescript ${ packageJSON . version } ` ) } ` ) ; // only log if we’re NOT writing to stdout
153
143
154
144
const pathToSpec = flags . _ [ 0 ] ;
155
145
@@ -173,12 +163,14 @@ async function main() {
173
163
174
164
// error: no matches for glob
175
165
if ( inputSpecPaths . length === 0 ) {
176
- errorAndExit ( `✘ Could not find any specs matching "${ pathToSpec } ". Please check that the path is correct.` ) ;
166
+ error ( `Could not find any specs matching "${ pathToSpec } ". Please check that the path is correct.` ) ;
167
+ process . exit ( 1 ) ;
177
168
}
178
169
179
170
// error: tried to glob output to single file
180
171
if ( isGlob && output === OUTPUT_FILE && fs . existsSync ( outputDir ) && fs . lstatSync ( outputDir ) . isFile ( ) ) {
181
- errorAndExit ( `✘ Expected directory for --output if using glob patterns. Received "${ flags . output } ".` ) ;
172
+ error ( `Expected directory for --output if using glob patterns. Received "${ flags . output } ".` ) ;
173
+ process . exit ( 1 ) ;
182
174
}
183
175
184
176
// generate schema(s) in parallel
0 commit comments