swagger-typescript-api 13.0.25 → 13.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/{chunk-NLO3XRFX.cjs → chunk-LI5RQUAL.cjs} +5 -5
- package/dist/{chunk-NLO3XRFX.cjs.map → chunk-LI5RQUAL.cjs.map} +1 -1
- package/dist/{chunk-TXFFSIK5.js → chunk-U2TAGTOU.js} +3 -3
- package/dist/{chunk-TXFFSIK5.js.map → chunk-U2TAGTOU.js.map} +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/lib.cjs +1 -1
- package/dist/lib.js +1 -1
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {consola}from'consola';import f from'lodash';import*as g from'typescript';import*as at from'prettier';import*as pt from'cosmiconfig';import*as ut from'nanoid';import*as dt from'js-yaml';import*as Tt from'swagger2openapi';import*as F from'node:path';import F__default from'node:path';import*as Pt from'node:url';import Pt__default from'node:url';import*as St from'eta';import*as C from'node:fs';var jt=Object.defineProperty;var Dt=(p,e)=>{for(var t in e)jt(p,t,{get:e[t],enumerable:true});};var ee=class{config;constructor(e){this.config=e;}removeUnusedImports=e=>{let t="file.ts",s=new Ke(t,e),a=g.createLanguageService(s).organizeImports({type:"file",fileName:t},{newLineCharacter:g.sys.newLine},void 0)[0];return a?.textChanges.length?a.textChanges.reduceRight((i,{span:o,newText:n})=>`${i.slice(0,o.start)}${n}${i.slice(o.start+o.length)}`,e):e};prettierFormat=async e=>await at.format(e,this.config.prettierOptions);formatCode=async(e,{removeUnusedImports:t=true,prettierFormat:s=true}={})=>(t&&(e=this.removeUnusedImports(e)),s&&(e=await this.prettierFormat(e)),e)},Ke=class{fileName;content;compilerOptions;constructor(e,t){this.fileName=e,this.content=t;let s=g.findConfigFile(e,g.sys.fileExists);this.compilerOptions=s?g.convertCompilerOptionsFromJson(g.readConfigFile(s,g.sys.readFile).config.compilerOptions,"").options:g.getDefaultCompilerOptions();}getNewLine(){return "newLine"in g.sys?g.sys.newLine:`
|
|
2
|
-
`}getScriptFileNames(){return [this.fileName]}getCompilationSettings(){return this.compilerOptions}getDefaultLibFileName(){return g.getDefaultLibFileName(this.getCompilationSettings())}getCurrentDirectory(){return process.cwd()}getScriptVersion(){return g.version}getScriptSnapshot(){return g.ScriptSnapshot.fromString(this.content)}readFile(e,t){return e===this.fileName?this.content:g.sys.readFile(e,t)}fileExists(e){return g.sys.fileExists(e)}};var b=class{reservedNames=[];getFallbackName;config;constructor(e,t,s){this.config=e,this.getFallbackName=s,this.reserve(t);}reserve(e){let t=f.uniq(f.compact(e));for(let s of t)this.reservedNames.indexOf(s)===-1&&this.reservedNames.push(s);}unreserve(e){this.reservedNames.filter(t=>!e.some(s=>s===t));}isReserved(e){return this.reservedNames.some(t=>t===e)}resolve(e,t,s,r=true){if(typeof t=="function"){let a=null;for(;a===null;){let i=t(e,s);if(i===void 0)return consola.warn("unable to resolve name. current reserved names: ",...this.reservedNames),null;(!r||!this.isReserved(i))&&(a=i);}return r&&this.reserve([a]),a}if(Array.isArray(e)){let a=null,i=f.uniq(f.compact(e));for(let o of i)!a&&(!r||!this.isReserved(o))&&(a=o);return a?(r&&this.reserve([a]),a):(consola.debug("trying to resolve name with using fallback name generator using variants",...e),this.resolve(e,this.getFallbackName,s))}return consola.debug("problem with reserving names. current reserved names: ",...this.reservedNames),null}};var _t=(p=0,e=1)=>Math.random()*(e-p)+p,it=(p=0,e=1)=>p===e?p:Math.round(_t(p,e));var se=class extends b{counter=1;fallbackNameCounter=1;countersByVariant=new Map;constructor(e,t){super(e,t,s=>{let r=s[it(0,s.length-1)];if(r){this.countersByVariant.has(r)||this.countersByVariant.set(r,0);let i=this.countersByVariant.get(r)+1;this.countersByVariant.set(r,i);let o=`${r}${i}`;return consola.debug("generated dirty resolved type name for component - ",o),o}let a=`${this.config.componentTypeNameResolver}${this.fallbackNameCounter++}`;return consola.debug("generated fallback type name for component - ",a),a});}};var ae={};Dt(ae,{DEFAULT_BODY_ARG_NAME:()=>Ue,FILE_PREFIX:()=>qt,HTTP_CLIENT:()=>L,PRETTIER_OPTIONS:()=>re,PROJECT_VERSION:()=>H,RESERVED_BODY_ARG_NAMES:()=>Ge,RESERVED_HEADER_ARG_NAMES:()=>We,RESERVED_PATH_ARG_NAMES:()=>Ve,RESERVED_QUERY_ARG_NAMES:()=>Be,RESERVED_REQ_PARAMS_ARG_NAMES:()=>Ut,SCHEMA_TYPES:()=>l});var ot={name:"swagger-typescript-api",version:"13.0.
|
|
2
|
+
`}getScriptFileNames(){return [this.fileName]}getCompilationSettings(){return this.compilerOptions}getDefaultLibFileName(){return g.getDefaultLibFileName(this.getCompilationSettings())}getCurrentDirectory(){return process.cwd()}getScriptVersion(){return g.version}getScriptSnapshot(){return g.ScriptSnapshot.fromString(this.content)}readFile(e,t){return e===this.fileName?this.content:g.sys.readFile(e,t)}fileExists(e){return g.sys.fileExists(e)}};var b=class{reservedNames=[];getFallbackName;config;constructor(e,t,s){this.config=e,this.getFallbackName=s,this.reserve(t);}reserve(e){let t=f.uniq(f.compact(e));for(let s of t)this.reservedNames.indexOf(s)===-1&&this.reservedNames.push(s);}unreserve(e){this.reservedNames.filter(t=>!e.some(s=>s===t));}isReserved(e){return this.reservedNames.some(t=>t===e)}resolve(e,t,s,r=true){if(typeof t=="function"){let a=null;for(;a===null;){let i=t(e,s);if(i===void 0)return consola.warn("unable to resolve name. current reserved names: ",...this.reservedNames),null;(!r||!this.isReserved(i))&&(a=i);}return r&&this.reserve([a]),a}if(Array.isArray(e)){let a=null,i=f.uniq(f.compact(e));for(let o of i)!a&&(!r||!this.isReserved(o))&&(a=o);return a?(r&&this.reserve([a]),a):(consola.debug("trying to resolve name with using fallback name generator using variants",...e),this.resolve(e,this.getFallbackName,s))}return consola.debug("problem with reserving names. current reserved names: ",...this.reservedNames),null}};var _t=(p=0,e=1)=>Math.random()*(e-p)+p,it=(p=0,e=1)=>p===e?p:Math.round(_t(p,e));var se=class extends b{counter=1;fallbackNameCounter=1;countersByVariant=new Map;constructor(e,t){super(e,t,s=>{let r=s[it(0,s.length-1)];if(r){this.countersByVariant.has(r)||this.countersByVariant.set(r,0);let i=this.countersByVariant.get(r)+1;this.countersByVariant.set(r,i);let o=`${r}${i}`;return consola.debug("generated dirty resolved type name for component - ",o),o}let a=`${this.config.componentTypeNameResolver}${this.fallbackNameCounter++}`;return consola.debug("generated fallback type name for component - ",a),a});}};var ae={};Dt(ae,{DEFAULT_BODY_ARG_NAME:()=>Ue,FILE_PREFIX:()=>qt,HTTP_CLIENT:()=>L,PRETTIER_OPTIONS:()=>re,PROJECT_VERSION:()=>H,RESERVED_BODY_ARG_NAMES:()=>Ge,RESERVED_HEADER_ARG_NAMES:()=>We,RESERVED_PATH_ARG_NAMES:()=>Ve,RESERVED_QUERY_ARG_NAMES:()=>Be,RESERVED_REQ_PARAMS_ARG_NAMES:()=>Ut,SCHEMA_TYPES:()=>l});var ot={name:"swagger-typescript-api",version:"13.0.26",description:"Generate the API client for Fetch or Axios from an OpenAPI Specification",homepage:"https://github.com/acacode/swagger-typescript-api",bugs:"https://github.com/acacode/swagger-typescript-api/issues",repository:"github:acacode/swagger-typescript-api",license:"MIT",author:"Sergey Volkov <js2me@outlook.com>",contributors:["Sora Morimoto <sora@morimoto.io>"],type:"module",exports:{".":{import:{default:"./dist/lib.js"},require:{default:"./dist/lib.cjs"}}},main:"./dist/lib.cjs",module:"./dist/lib.js",bin:{sta:"./dist/cli.js","swagger-typescript-api":"./dist/cli.js"},files:["dist","templates"],scripts:{build:"tsup","cli:help":"node index.js -h","cli:json":"node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts","cli:yaml":"node index.js -r -d -p ./swagger-test-cli.yaml -n swagger-test-cli.ts",format:"biome format --write .","format:check":"biome format .",lint:"biome check",prepack:"tsup",test:"vitest run"},dependencies:{"@types/swagger-schema-official":"^2.0.25",citty:"^0.1.6",consola:"^3.4.2",cosmiconfig:"^9.0.0",eta:"^2.2.0","js-yaml":"^4.1.0",lodash:"^4.17.21",nanoid:"^5.1.5",prettier:"~3.5.3","swagger-schema-official":"2.0.0-bab6bed",swagger2openapi:"^7.0.8",typescript:"~5.8.2"},devDependencies:{"@biomejs/biome":"1.9.4","@changesets/changelog-github":"0.5.1","@changesets/cli":"2.28.1","@tsconfig/node18":"18.2.4","@tsconfig/strictest":"2.0.5","@types/js-yaml":"4.0.9","@types/lodash":"4.17.16","@types/node":"22.13.12","@types/swagger2openapi":"7.0.4",axios:"1.8.4","openapi-types":"12.1.3",tsup:"8.4.0",vitest:"3.0.9"},packageManager:"yarn@4.7.0",engines:{node:">=18.0.0"},publishConfig:{access:"public",registry:"https://registry.npmjs.org"}};var Ue="data",qt=`/* eslint-disable */
|
|
3
3
|
/* tslint:disable */
|
|
4
4
|
// @ts-nocheck
|
|
5
5
|
/*
|
|
@@ -38,5 +38,5 @@ ${e}
|
|
|
38
38
|
|
|
39
39
|
`,W=class{getFileContent=e=>C.readFileSync(e,{encoding:"utf8"});readDir=e=>C.readdirSync(e);pathIsDir=e=>{if(!e)return false;try{return C.statSync(e).isDirectory()}catch{return false}};cropExtension=e=>{let t=e.split(".");return t.length>1&&t.pop(),t.join(".")};removeDir=e=>{try{typeof C.rmSync=="function"?C.rmSync(e,{recursive:!0}):C.rmdirSync(e,{recursive:!0});}catch(t){consola.debug("failed to remove dir",t);}};createDir=e=>{try{C.mkdirSync(e,{recursive:!0});}catch(t){consola.debug("failed to create dir",t);}};cleanDir=e=>{this.removeDir(e),this.createDir(e);};pathIsExist=e=>!!e&&C.existsSync(e);createFile=({path:e,fileName:t,content:s,withPrefix:r})=>{let a=F.dirname(Pt.fileURLToPath(import.meta.url)),i=F.resolve(a,e,`./${t}`),o=`${r?zt:""}${s}`;return C.writeFileSync(i,o)}};var Zt=["schemaWalker","swaggerSchemaResolver","schemaComponentsMap","typeNameFormatter","templatesWorker","codeFormatter","schemaParserFabric","schemaRoutes","javascriptTranslator"],ve=class{config;swaggerSchemaResolver;schemaComponentsMap;typeNameFormatter;schemaParserFabric;schemaRoutes;fileSystem;codeFormatter;templatesWorker;schemaWalker;javascriptTranslator;constructor(e){this.config=new ie(e),this.fileSystem=new W,this.swaggerSchemaResolver=new be(this.config,this.fileSystem),this.schemaWalker=new xe(this.config,this.swaggerSchemaResolver),this.schemaComponentsMap=new oe(this.config),this.typeNameFormatter=new Me(this.config),this.templatesWorker=new Ae(this.config,this.fileSystem,this.getRenderTemplateData),this.codeFormatter=new ee(this.config),this.schemaParserFabric=new Re(this.config,this.templatesWorker,this.schemaComponentsMap,this.typeNameFormatter,this.schemaWalker),this.schemaRoutes=new Fe(this.config,this.schemaParserFabric,this.schemaComponentsMap,this.templatesWorker,this.typeNameFormatter),this.javascriptTranslator=new Ie(this.config,this.codeFormatter);}async start(){this.config.update({templatePaths:this.templatesWorker.getTemplatePaths(this.config)}),this.config.update({templatesToRender:this.templatesWorker.getTemplates(this.config)});let e=await this.swaggerSchemaResolver.create();this.swaggerSchemaResolver.fixSwaggerSchema(e),this.config.update({swaggerSchema:e.usageSchema,originalSchema:e.originalSchema}),this.schemaWalker.addSchema("$usage",e.usageSchema),this.schemaWalker.addSchema("$original",e.originalSchema),consola.info("start generating your typescript api"),this.config.update(this.config.hooks.onInit(this.config,this)||this.config),this.schemaComponentsMap.clear(),f.each(e.usageSchema.components,(n,c)=>f.each(n,(h,m)=>{this.schemaComponentsMap.createComponent(this.schemaComponentsMap.createRef(["components",c,m]),h);}));let s=this.schemaComponentsMap.filter(f.compact(["schemas",this.config.extractResponses&&"responses"])).map(n=>{let c=this.schemaParserFabric.parseSchema(n.rawTypeData,n.typeName);return n.typeData=c,c});this.schemaRoutes.attachSchema({usageSchema:e.usageSchema,parsedSchemas:s});let r={apiConfig:this.createApiConfig(e.usageSchema),config:this.config,modelTypes:this.collectModelTypes(),hasSecurityRoutes:this.schemaRoutes.hasSecurityRoutes,hasQueryRoutes:this.schemaRoutes.hasQueryRoutes,hasFormDataRoutes:this.schemaRoutes.hasFormDataRoutes,generateResponses:this.config.generateResponses,routes:this.schemaRoutes.getGroupedRoutes(),extraTemplates:this.config.extraTemplates,fileName:this.config.fileName,translateToJavaScript:this.config.toJS,customTranslator:this.config.customTranslator?new this.config.customTranslator:null,utils:this.getRenderTemplateData().utils},a=this.config.hooks.onPrepareConfig(r)||r;this.fileSystem.pathIsExist(this.config.output)?this.config.cleanOutput&&(consola.debug("cleaning dir",this.config.output),this.fileSystem.cleanDir(this.config.output)):(consola.debug(`path ${this.config.output} is not exist. creating dir by this path`),this.fileSystem.createDir(this.config.output));let i=await this.generateOutputFiles({configuration:a});if(this.fileSystem.pathIsDir(this.config.output))for(let n of i)this.fileSystem.createFile({path:this.config.output,fileName:`${n.fileName}${n.fileExtension}`,content:n.fileContent,withPrefix:true}),consola.success("api file",`"${n.fileName}${n.fileExtension}"`,`created in ${this.config.output}`);return {files:i,configuration:a,getTemplate:this.templatesWorker.getTemplate,renderTemplate:this.templatesWorker.renderTemplate,createFile:this.fileSystem.createFile,formatTSContent:this.codeFormatter.formatCode}}getRenderTemplateData=()=>({utils:{Ts:this.config.Ts,formatDescription:this.schemaParserFabric.schemaFormatters.formatDescription,internalCase:X,classNameCase:A,pascalCase:A,getInlineParseContent:this.schemaParserFabric.getInlineParseContent,getParseContent:this.schemaParserFabric.getParseContent,getComponentByRef:this.schemaComponentsMap.get,parseSchema:this.schemaParserFabric.parseSchema,checkAndAddNull:this.schemaParserFabric.schemaUtils.safeAddNullToType,safeAddNullToType:this.schemaParserFabric.schemaUtils.safeAddNullToType,isNeedToAddNull:this.schemaParserFabric.schemaUtils.isNullMissingInType,inlineExtraFormatters:this.schemaParserFabric.schemaFormatters.inline,formatters:this.schemaParserFabric.schemaFormatters.base,formatModelName:this.typeNameFormatter.format,fmtToJSDocLine:(e,{eol:t=true})=>` * ${e}${t?`
|
|
40
40
|
`:""}`,NameResolver:b,_:f,require:this.templatesWorker.requireFnFromTemplate},config:this.config});collectModelTypes=()=>{let e=this.schemaComponentsMap.getComponents(),t=[],s=f.compact(["schemas",this.config.extractResponses&&"responses"]),r=()=>this.schemaComponentsMap.filter(...s).length,a=r(),i=0;for(;i<a;){t=[],i=0;for(let o of e)if(s.includes(o.componentName)){let n=this.prepareModelType(o);n&&t.push(n),i++;}a=r();}return this.config.sortTypes?t.sort(me("name")):t};prepareModelType=e=>{if(e.$prepared)return e.$prepared;e.typeData||(e.typeData=this.schemaParserFabric.parseSchema(e.rawTypeData,e.typeName));let t=e.typeData,s=this.schemaParserFabric.schemaFormatters.base[t.type]?this.schemaParserFabric.schemaFormatters.base[t.type](t):t,{typeIdentifier:r,name:a,content:i,description:o}=s,n=this.typeNameFormatter.format(a);if(n===null)return null;let c={...s,typeIdentifier:r,name:n,description:o,$content:t.content,rawContent:t.content,content:i,typeData:s};return e.$prepared=c,c};generateOutputFiles=async({configuration:e})=>{let{modular:t,templatesToRender:s}=this.config,r=t?await this.createMultipleFileInfos(s,e):await this.createSingleFileInfo(s,e);if(!f.isEmpty(e.extraTemplates))for(let a of e.extraTemplates){let i=this.templatesWorker.renderTemplate(this.fileSystem.getFileContent(a.path),e);r.push(...await this.createOutputFileInfo(e,a.name,i));}return r.filter(a=>!!a&&!!a.fileContent)};createMultipleFileInfos=async(e,t)=>{let{routes:s}=t,{fileNames:r,generateRouteTypes:a,generateClient:i}=t.config,o=[];if(s.$outOfModule){if(a){let n=this.templatesWorker.renderTemplate(e.routeTypes,{...t,route:t.routes.$outOfModule});o.push(...await this.createOutputFileInfo(t,r.outOfModuleApi,n));}if(i){let n=this.templatesWorker.renderTemplate(e.api,{...t,route:t.routes.$outOfModule});o.push(...await this.createOutputFileInfo(t,r.outOfModuleApi,n));}}if(s.combined)for(let n of s.combined){if(a){let c=this.templatesWorker.renderTemplate(e.routeTypes,{...t,route:n});o.push(...await this.createOutputFileInfo(t,A(`${n.moduleName}_Route`),c));}if(i){let c=this.templatesWorker.renderTemplate(e.api,{...t,route:n});o.push(...await this.createOutputFileInfo(t,A(n.moduleName),c));}}return [...await this.createOutputFileInfo(t,r.dataContracts,this.templatesWorker.renderTemplate(e.dataContracts,t)),...i?await this.createOutputFileInfo(t,r.httpClient,this.templatesWorker.renderTemplate(e.httpClient,t)):[],...o]};createSingleFileInfo=async(e,t)=>{let{generateRouteTypes:s,generateClient:r}=t.config;return await this.createOutputFileInfo(t,t.fileName,f.compact([this.templatesWorker.renderTemplate(e.dataContracts,t),s&&this.templatesWorker.renderTemplate(e.routeTypes,t),r&&this.templatesWorker.renderTemplate(e.httpClient,t),r&&this.templatesWorker.renderTemplate(e.api,t)]).join(`
|
|
41
|
-
`))};createOutputFileInfo=async(e,t,s)=>{let r=this.fileSystem.cropExtension(t),a=g.Extension.Ts;return e.translateToJavaScript?(consola.debug("using js translator for",r),await this.javascriptTranslator.translate({fileName:r,fileExtension:a,fileContent:s})):e.customTranslator?(consola.debug("using custom translator for",r),await e.customTranslator.translate({fileName:r,fileExtension:a,fileContent:s})):(consola.debug("generating output for",`${r}${a}`),[{fileName:r,fileExtension:a,fileContent:await this.codeFormatter.formatCode(s)}])};createApiConfig=e=>{let{info:t,servers:s,host:r,basePath:a,externalDocs:i,tags:o}=e,n=s?.[0]||{url:""},{title:c="No title",version:h}=t||{},{url:m}=n;return {info:t||{},servers:s||[],basePath:a,host:r,externalDocs:f.merge({url:"",description:""},i),tags:f.compact(o),baseUrl:m,title:c,version:h}};injectClassInstance=(e,t)=>{this[e]=t;for(let s of Zt)s!==e&&e in this[s]&&(this[s][e]=t);}};var ke=class{cleanOutput=false;output=void 0;httpClientType=L.FETCH;modular=false;rewrite=false;silent=false;debug=false;version=H;constructor(e){this.update(e);}update=e=>{K(this,e);}};var ts=F__default.dirname(Pt__default.fileURLToPath(import.meta.url)),je=class{config;fileSystem;rootDir=F__default.resolve(ts,"../../../");paths={baseTemplates:"templates/base",httpClientTemplates:"templates/base/http-clients",moduleApiTemplates:"templates/modular",defaultApiTemplates:"templates/default"};importTemplatePrefixes=["@base","@modular","@default"];constructor(e){this.config=new ke(e),this.fileSystem=new W;}async start(){consola.info('start generating source templates ".ejs" for code generator');let e=this.getTemplates();if(this.config.output){consola.info("preparing output directory for source templates");let t=F__default.resolve(process.cwd(),this.config.output);this.fileSystem.pathIsExist(t)?this.config.cleanOutput&&this.fileSystem.cleanDir(t):this.fileSystem.createDir(t);for(let s of e){let r=this.fileSystem.cropExtension(s.name),a=F__default.resolve(t,`${r}.ejs`),i=F__default.resolve(t,`${r}.eta`),o=this.fileSystem.pathIsExist(a),n=this.fileSystem.pathIsExist(i);!o&&!n?this.fileSystem.createFile({path:t,fileName:s.name,content:s.content,withPrefix:false}):this.config.rewrite&&(o?this.fileSystem.createFile({path:t,fileName:`${r}.ejs`,content:s.content,withPrefix:false}):n&&this.fileSystem.createFile({path:t,fileName:`${r}.eta`,content:s.content,withPrefix:false}));}consola.success(`source templates has been successfully created in "${t}"`);}return {files:e,configuration:this.config,createFile:this.fileSystem.createFile}}getTemplates=()=>{let e=[],t=this.getTemplateNamesFromDir(this.paths.baseTemplates),s=this.getTemplateNamesFromDir(this.paths.httpClientTemplates),r=this.config.modular?this.paths.moduleApiTemplates:this.paths.defaultApiTemplates,a=this.getTemplateNamesFromDir(r),i=s.find(n=>n.startsWith(`${this.config.httpClientType}-`)),o="";i&&(o=this.fixTemplateContent(this.getTemplateContent(`${this.paths.httpClientTemplates}/${i}`)));for(let n of t){let c=n==="http-client.ejs"&&o||this.fixTemplateContent(this.getTemplateContent(`${this.paths.baseTemplates}/${n}`));e.push({name:n,content:c});}for(let n of a)e.push({name:n,content:this.fixTemplateContent(this.getTemplateContent(`${r}/${n}`))});return e};fixTemplateContent=e=>{let t=new RegExp(`includeFile\\("(${this.importTemplatePrefixes.map(a=>`(${a})`).join("|")})/`,"g"),s=new RegExp(`includeFile\\(\`(${this.importTemplatePrefixes.map(a=>`(${a})`).join("|")})/`,"g"),r=new RegExp(`includeFile\\('(${this.importTemplatePrefixes.map(a=>`(${a})`).join("|")})/`,"g");return e.replace(t,'includeFile("./').replace(s,"includeFile(`./").replace(r,"includeFile('./")};getTemplateNamesFromDir=e=>this.fileSystem.readDir(F__default.resolve(this.rootDir,e)).filter(t=>t.endsWith(".ejs"));getTemplateContent=e=>this.fileSystem.getFileContent(F__default.resolve(this.rootDir,e))};async function ss(p){return p.debug&&(consola.level=Number.MAX_SAFE_INTEGER),p.silent&&(consola.level=0),await new je(p).start()}async function Va(p){return p.debug&&(consola.level=Number.MAX_SAFE_INTEGER),p.silent&&(consola.level=0),await new ve(p).start()}export{ot as a,L as b,ae as c,ie as d,ke as e,ss as f,Va as g};//# sourceMappingURL=chunk-
|
|
42
|
-
//# sourceMappingURL=chunk-
|
|
41
|
+
`))};createOutputFileInfo=async(e,t,s)=>{let r=this.fileSystem.cropExtension(t),a=g.Extension.Ts;return e.translateToJavaScript?(consola.debug("using js translator for",r),await this.javascriptTranslator.translate({fileName:r,fileExtension:a,fileContent:s})):e.customTranslator?(consola.debug("using custom translator for",r),await e.customTranslator.translate({fileName:r,fileExtension:a,fileContent:s})):(consola.debug("generating output for",`${r}${a}`),[{fileName:r,fileExtension:a,fileContent:await this.codeFormatter.formatCode(s)}])};createApiConfig=e=>{let{info:t,servers:s,host:r,basePath:a,externalDocs:i,tags:o}=e,n=s?.[0]||{url:""},{title:c="No title",version:h}=t||{},{url:m}=n;return {info:t||{},servers:s||[],basePath:a,host:r,externalDocs:f.merge({url:"",description:""},i),tags:f.compact(o),baseUrl:m,title:c,version:h}};injectClassInstance=(e,t)=>{this[e]=t;for(let s of Zt)s!==e&&e in this[s]&&(this[s][e]=t);}};var ke=class{cleanOutput=false;output=void 0;httpClientType=L.FETCH;modular=false;rewrite=false;silent=false;debug=false;version=H;constructor(e){this.update(e);}update=e=>{K(this,e);}};var ts=F__default.dirname(Pt__default.fileURLToPath(import.meta.url)),je=class{config;fileSystem;rootDir=F__default.resolve(ts,"../../../");paths={baseTemplates:"templates/base",httpClientTemplates:"templates/base/http-clients",moduleApiTemplates:"templates/modular",defaultApiTemplates:"templates/default"};importTemplatePrefixes=["@base","@modular","@default"];constructor(e){this.config=new ke(e),this.fileSystem=new W;}async start(){consola.info('start generating source templates ".ejs" for code generator');let e=this.getTemplates();if(this.config.output){consola.info("preparing output directory for source templates");let t=F__default.resolve(process.cwd(),this.config.output);this.fileSystem.pathIsExist(t)?this.config.cleanOutput&&this.fileSystem.cleanDir(t):this.fileSystem.createDir(t);for(let s of e){let r=this.fileSystem.cropExtension(s.name),a=F__default.resolve(t,`${r}.ejs`),i=F__default.resolve(t,`${r}.eta`),o=this.fileSystem.pathIsExist(a),n=this.fileSystem.pathIsExist(i);!o&&!n?this.fileSystem.createFile({path:t,fileName:s.name,content:s.content,withPrefix:false}):this.config.rewrite&&(o?this.fileSystem.createFile({path:t,fileName:`${r}.ejs`,content:s.content,withPrefix:false}):n&&this.fileSystem.createFile({path:t,fileName:`${r}.eta`,content:s.content,withPrefix:false}));}consola.success(`source templates has been successfully created in "${t}"`);}return {files:e,configuration:this.config,createFile:this.fileSystem.createFile}}getTemplates=()=>{let e=[],t=this.getTemplateNamesFromDir(this.paths.baseTemplates),s=this.getTemplateNamesFromDir(this.paths.httpClientTemplates),r=this.config.modular?this.paths.moduleApiTemplates:this.paths.defaultApiTemplates,a=this.getTemplateNamesFromDir(r),i=s.find(n=>n.startsWith(`${this.config.httpClientType}-`)),o="";i&&(o=this.fixTemplateContent(this.getTemplateContent(`${this.paths.httpClientTemplates}/${i}`)));for(let n of t){let c=n==="http-client.ejs"&&o||this.fixTemplateContent(this.getTemplateContent(`${this.paths.baseTemplates}/${n}`));e.push({name:n,content:c});}for(let n of a)e.push({name:n,content:this.fixTemplateContent(this.getTemplateContent(`${r}/${n}`))});return e};fixTemplateContent=e=>{let t=new RegExp(`includeFile\\("(${this.importTemplatePrefixes.map(a=>`(${a})`).join("|")})/`,"g"),s=new RegExp(`includeFile\\(\`(${this.importTemplatePrefixes.map(a=>`(${a})`).join("|")})/`,"g"),r=new RegExp(`includeFile\\('(${this.importTemplatePrefixes.map(a=>`(${a})`).join("|")})/`,"g");return e.replace(t,'includeFile("./').replace(s,"includeFile(`./").replace(r,"includeFile('./")};getTemplateNamesFromDir=e=>this.fileSystem.readDir(F__default.resolve(this.rootDir,e)).filter(t=>t.endsWith(".ejs"));getTemplateContent=e=>this.fileSystem.getFileContent(F__default.resolve(this.rootDir,e))};async function ss(p){return p.debug&&(consola.level=Number.MAX_SAFE_INTEGER),p.silent&&(consola.level=0),await new je(p).start()}async function Va(p){return p.debug&&(consola.level=Number.MAX_SAFE_INTEGER),p.silent&&(consola.level=0),await new ve(p).start()}export{ot as a,L as b,ae as c,ie as d,ke as e,ss as f,Va as g};//# sourceMappingURL=chunk-U2TAGTOU.js.map
|
|
42
|
+
//# sourceMappingURL=chunk-U2TAGTOU.js.map
|