@@ -18,6 +18,7 @@ import { KNOWN_IMPORTS } from './knownImports';
1818import { findSymbolInitializer } from './resolveInit' ;
1919import { parseCodecInitializer } from './codec' ;
2020import { SourceFile } from './sourceFile' ;
21+ import { logError , logInfo , logWarn } from './error' ;
2122
2223const app = command ( {
2324 name : 'api-ts' ,
@@ -87,7 +88,7 @@ const app = command({
8788 const codecFilePath = p . resolve ( codecFile ) ;
8889 const codecModule = await import ( codecFilePath ) ;
8990 if ( codecModule . default === undefined ) {
90- console . error ( `[ERROR] Could not find default export in ${ codecFilePath } `) ;
91+ logError ( ` Could not find default export in ${ codecFilePath } `) ;
9192 process . exit ( 1 ) ;
9293 }
9394 const customCodecs = codecModule . default ( E ) ;
@@ -96,13 +97,13 @@ const app = command({
9697
9798 const project = await new Project ( { } , knownImports ) . parseEntryPoint ( filePath ) ;
9899 if ( E . isLeft ( project ) ) {
99- console . error ( `[ERROR] ${ project . left } `) ;
100+ logError ( ` ${ project . left } `) ;
100101 process . exit ( 1 ) ;
101102 }
102103
103104 const entryPoint = project . right . get ( filePath ) ;
104105 if ( entryPoint === undefined ) {
105- console . error ( `[ERROR] Could not find entry point ${ filePath } `) ;
106+ logError ( ` Could not find entry point ${ filePath } `) ;
106107 process . exit ( 1 ) ;
107108 }
108109
@@ -119,22 +120,20 @@ const app = command({
119120 symbol . init . callee . type === 'Super' ||
120121 symbol . init . callee . type === 'Import'
121122 ) {
122- console . error (
123- `[WARN] Skipping ${ symbol . name } because it is a ${ symbol . init . callee . type } ` ,
124- ) ;
123+ logWarn ( `Skipping ${ symbol . name } because it is a ${ symbol . init . callee . type } ` ) ;
125124 continue ;
126125 } else if ( ! isApiSpec ( entryPoint , symbol . init . callee ) ) {
127126 continue ;
128127 }
129- console . error ( `[INFO] Found API spec in ${ symbol . name } ` ) ;
128+ logInfo ( `[INFO] Found API spec in ${ symbol . name } ` ) ;
130129
131130 const result = parseApiSpec (
132131 project . right ,
133132 entryPoint ,
134133 symbol . init . arguments [ 0 ] ! . expression ,
135134 ) ;
136135 if ( E . isLeft ( result ) ) {
137- console . error ( `[ERROR] Error when parsing ${ symbol . name } : ${ result . left } `) ;
136+ logError ( ` Error when parsing ${ symbol . name } : ${ result . left } `) ;
138137 process . exit ( 1 ) ;
139138 }
140139
@@ -145,7 +144,7 @@ const app = command({
145144 apiSpec . push ( ...result . right ) ;
146145 }
147146 if ( apiSpec . length === 0 ) {
148- console . error ( `[ERROR] Could not find API spec in ${ filePath } `) ;
147+ logError ( ` Could not find API spec in ${ filePath } `) ;
149148 process . exit ( 1 ) ;
150149 }
151150
@@ -166,7 +165,7 @@ const app = command({
166165 }
167166 const sourceFile = project . right . get ( ref . location ) ;
168167 if ( sourceFile === undefined ) {
169- console . error ( `[ERROR] Could not find '${ ref . name } ' from '${ ref . location } '`) ;
168+ logError ( ` Could not find '${ ref . name } ' from '${ ref . location } '`) ;
170169 process . exit ( 1 ) ;
171170 }
172171
0 commit comments