@@ -5,10 +5,7 @@ import { URL } from "node:url";
55import glob from "fast-glob" ;
66import parser from "yargs-parser" ;
77import 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" ;
129
1310const HELP = `Usage
1411 $ openapi-typescript [input] [options]
@@ -38,11 +35,6 @@ const HTTP_RE = /^https?:\/\//;
3835
3936const timeStart = process . hrtime ( ) ;
4037
41- function errorAndExit ( errorMessage ) {
42- process . exitCode = 1 ; // needed for async functions
43- throw new Error ( errorMessage ) ;
44- }
45-
4638const [ , , ...args ] = process . argv ;
4739if ( args . includes ( "-ap" ) ) errorAndExit ( `The -ap alias has been deprecated. Use "--additional-properties" instead.` ) ;
4840if ( args . includes ( "-it" ) ) errorAndExit ( `The -it alias has been deprecated. Use "--immutable-types" instead.` ) ;
@@ -123,7 +115,7 @@ async function generateSchema(pathToSpec) {
123115
124116 const timeEnd = process . hrtime ( timeStart ) ;
125117 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]` ) } ` ) ;
127119 } else {
128120 process . stdout . write ( result ) ;
129121 // if stdout, (still) don’t log anything to console!
@@ -147,9 +139,7 @@ async function main() {
147139 let outputFile = new URL ( flags . output , CWD ) ;
148140 let outputDir = new URL ( "." , outputFile ) ;
149141
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
153143
154144 const pathToSpec = flags . _ [ 0 ] ;
155145
@@ -173,12 +163,14 @@ async function main() {
173163
174164 // error: no matches for glob
175165 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 ) ;
177168 }
178169
179170 // error: tried to glob output to single file
180171 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 ) ;
182174 }
183175
184176 // generate schema(s) in parallel
0 commit comments