11import * as path from "node:path" ;
2+ import * as url from "node:url" ;
23import { defineCommand , runMain } from "citty" ;
34import { consola } from "consola" ;
45import packageJson from "./package.json" with { type : "json" } ;
@@ -53,6 +54,9 @@ const generateTemplatesCommand = defineCommand({
5354 } ,
5455 } ,
5556 run : async ( { args } ) => {
57+ if ( args . debug ) consola . level = Number . MAX_SAFE_INTEGER ;
58+ if ( args . silent ) consola . level = 0 ;
59+
5660 await generateTemplates ( {
5761 cleanOutput : args [ "clean-output" ] ,
5862 httpClientType : args [ "http-client" ] ,
@@ -175,27 +179,17 @@ const generateCommand = defineCommand({
175179 type : "string" ,
176180 description :
177181 "determines which path index should be used for routes separation (example: GET:/fruits/getFruit -> index:0 -> moduleName -> fruits)" ,
178- default : codeGenBaseConfig . moduleNameIndex ,
182+ default : codeGenBaseConfig . moduleNameIndex . toString ( ) ,
179183 } ,
180184 "module-name-first-tag" : {
181185 type : "boolean" ,
182186 description : "splits routes based on the first tag" ,
183187 default : codeGenBaseConfig . moduleNameFirstTag ,
184188 } ,
185- disableStrictSSL : {
186- type : "boolean" ,
187- description : "disabled strict SSL" ,
188- default : codeGenBaseConfig . disableStrictSSL ,
189- } ,
190- disableProxy : {
191- type : "boolean" ,
192- description : "disabled proxy" ,
193- default : codeGenBaseConfig . disableProxy ,
194- } ,
195189 axios : {
196190 type : "boolean" ,
197191 description : "generate axios http client" ,
198- default : codeGenBaseConfig . httpClientType === HTTP_CLIENT . AXIOS ,
192+ default : false ,
199193 } ,
200194 "unwrap-response-data" : {
201195 type : "boolean" ,
@@ -223,12 +217,12 @@ const generateCommand = defineCommand({
223217 default : codeGenBaseConfig . defaultResponseType ,
224218 } ,
225219 "type-prefix" : {
226- type : "boolean " ,
220+ type : "string " ,
227221 description : "data contract name prefix" ,
228222 default : codeGenBaseConfig . typePrefix ,
229223 } ,
230224 "type-suffix" : {
231- type : "boolean " ,
225+ type : "string " ,
232226 description : "data contract name suffix" ,
233227 default : codeGenBaseConfig . typeSuffix ,
234228 } ,
@@ -277,27 +271,29 @@ const generateCommand = defineCommand({
277271 "custom-config" : {
278272 type : "string" ,
279273 description : "custom config: primitiveTypeConstructs, hooks, ... " ,
280- default : "" ,
281274 } ,
282275 } ,
283276 run : async ( { args } ) => {
284- let customConfig = null ;
285- let customConfigPath : string | undefined ;
277+ if ( args . debug ) consola . level = Number . MAX_SAFE_INTEGER ;
278+ if ( args . silent ) consola . level = 0 ;
279+
280+ let customConfig ;
286281
287282 if ( args [ "custom-config" ] ) {
288283 try {
289- customConfigPath = path . resolve ( process . cwd ( ) , args [ "custom-config" ] ) ;
284+ const customConfigPath = url
285+ . pathToFileURL ( path . resolve ( process . cwd ( ) , args [ "custom-config" ] ) )
286+ . toString ( ) ;
290287 customConfig = await import ( customConfigPath ) ;
291288 customConfig = customConfig . default || customConfig ;
289+ if ( customConfig ) {
290+ consola . info ( `Found custom config at: ${ customConfigPath } ` ) ;
291+ }
292292 } catch ( error ) {
293293 consola . error ( "Error loading custom config:" , error ) ;
294294 }
295295 }
296296
297- if ( customConfig ) {
298- consola . info ( `Found custom config at: ${ customConfigPath } ` ) ;
299- }
300-
301297 await generateApi ( {
302298 addReadonly : args [ "add-readonly" ] ,
303299 anotherArrayType : args [ "another-array-type" ] ,
@@ -306,8 +302,6 @@ const generateCommand = defineCommand({
306302 debug : args . debug ,
307303 defaultResponseAsSuccess : args [ "default-as-success" ] ,
308304 defaultResponseType : args [ "default-response" ] ,
309- disableProxy : args . disableProxy ,
310- disableStrictSSL : args . disableStrictSSL ,
311305 disableThrowOnError : args [ "disable-throw-on-error" ] ,
312306 enumNamesAsValues : args [ "enum-names-as-values" ] ,
313307 extractEnums : args [ "extract-enums" ] ,
@@ -325,11 +319,11 @@ const generateCommand = defineCommand({
325319 args [ "http-client" ] || args . axios
326320 ? HTTP_CLIENT . AXIOS
327321 : HTTP_CLIENT . FETCH ,
328- input : path . resolve ( process . cwd ( ) , args . path ) ,
322+ input : path . resolve ( process . cwd ( ) , args . path as string ) ,
329323 modular : args . modular ,
330324 moduleNameFirstTag : args [ "module-name-first-tag" ] ,
331325 moduleNameIndex : + args [ "module-name-index" ] || 0 ,
332- output : path . resolve ( process . cwd ( ) , args . output || "." ) ,
326+ output : path . resolve ( process . cwd ( ) , ( args . output as string ) || "." ) ,
333327 patch : args . patch ,
334328 silent : args . silent ,
335329 singleHttpClient : args [ "single-http-client" ] ,
0 commit comments