anl 1.3.25 → 1.3.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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e="1.3.25",i="FE command line tool",s="bin/an-cli.js",t={dev:"rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript -w",build:"rimraf lib && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",pub:"bash publish.sh",ts:"tsc ./src/int.ts --noEmit --watch"},p={anl:"bin/an-cli.js"},l="Gleason <bianliuzhu@gmail.com>",r={"@commitlint/cli":"^17.4.3","@commitlint/config-conventional":"^17.4.3","@rollup/plugin-commonjs":"^21.0.1","@rollup/plugin-json":"^4.1.0","@rollup/plugin-node-resolve":"^13.1.3","@rollup/plugin-typescript":"^8.3.0","@types/inquirer":"^9.0.3","@types/shelljs":"^0.8.11","@typescript-eslint/eslint-plugin":"^5.52.0","@typescript-eslint/parser":"^5.52.0","cross-env":"^7.0.3",eslint:"^8.7.0",husky:"^8.0.3","openapi-types":"^12.1.3",prettier:"^3.3.2",rimraf:"^5.0.7",rollup:"^2.64.0","rollup-plugin-cleandir":"^2.0.0","rollup-plugin-terser":"^7.0.2",typescript:"^4.5.4"},o={"app-root-path":"^3.1.0",cac:"^6.7.12",chalk:"4.*","clear-console":"^1.1.0",commander:"^10.0.0",figures:"^6.1.0",inquirer:"^10.1.8","log-symbols":"^5.1.0",ora:"5.*","progress-estimator":"^0.3.0",shelljs:"^0.8.5"},n=["typescript","cli","typescript 脚手架","ts 脚手架","ts-cli","脚手架"],c=["package.json","README.md","lib","template"],u={type:"git",url:"https://github.com/bianliuzhu/an-cli.git"},a="commonjs",g={name:"anl",version:e,description:i,main:s,scripts:t,bin:p,author:l,license:"ISC",devDependencies:r,dependencies:o,keywords:n,files:c,repository:u,type:a};exports.author=l,exports.bin=p,exports.default=g,exports.dependencies=o,exports.description=i,exports.devDependencies=r,exports.files=c,exports.keywords=n,exports.license="ISC",exports.main=s,exports.name="anl",exports.repository=u,exports.scripts=t,exports.type=a,exports.version=e;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e="1.3.26",i="FE command line tool",s="bin/an-cli.js",t={dev:"rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript -w",build:"rimraf lib && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",pub:"bash publish.sh",ts:"tsc ./src/int.ts --noEmit --watch"},p={anl:"bin/an-cli.js"},l="Gleason <bianliuzhu@gmail.com>",r={"@commitlint/cli":"^17.4.3","@commitlint/config-conventional":"^17.4.3","@rollup/plugin-commonjs":"^21.0.1","@rollup/plugin-json":"^4.1.0","@rollup/plugin-node-resolve":"^13.1.3","@rollup/plugin-typescript":"^8.3.0","@types/inquirer":"^9.0.3","@types/shelljs":"^0.8.11","@typescript-eslint/eslint-plugin":"^5.52.0","@typescript-eslint/parser":"^5.52.0","cross-env":"^7.0.3",eslint:"^8.7.0",husky:"^8.0.3","openapi-types":"^12.1.3",prettier:"^3.3.2",rimraf:"^5.0.7",rollup:"^2.64.0","rollup-plugin-cleandir":"^2.0.0","rollup-plugin-terser":"^7.0.2",typescript:"^4.5.4"},o={"app-root-path":"^3.1.0",cac:"^6.7.12",chalk:"4.*","clear-console":"^1.1.0",commander:"^10.0.0",figures:"^6.1.0",inquirer:"^10.1.8","log-symbols":"^5.1.0",ora:"5.*","progress-estimator":"^0.3.0",shelljs:"^0.8.5"},n=["typescript","cli","typescript 脚手架","ts 脚手架","ts-cli","脚手架"],c=["package.json","README.md","lib","template"],u={type:"git",url:"https://github.com/bianliuzhu/an-cli.git"},a="commonjs",g={name:"anl",version:e,description:i,main:s,scripts:t,bin:p,author:l,license:"ISC",devDependencies:r,dependencies:o,keywords:n,files:c,repository:u,type:a};exports.author=l,exports.bin=p,exports.default=g,exports.dependencies=o,exports.description=i,exports.devDependencies=r,exports.files=c,exports.keywords=n,exports.license="ISC",exports.main=s,exports.name="anl",exports.repository=u,exports.scripts=t,exports.type=a,exports.version=e;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../utils/index.js");const t="\t";var s;!function(e){e.GET="get",e.PUT="put",e.POST="post",e.DELETE="delete",e.OPTIONS="options",e.HEAD="head",e.PATCH="patch",e.TRACE="trace"}(s||(s={}));const n={payload:{path:[],query:[],body:[]},response:"",_response:"",fileName:"",apiName:"",typeName:"",method:"",requestPath:"",summary:""};class r{pathsObject={};nonArrayType=["boolean","object","number","string","integer"];pathKey="";contentBody=n;Map=new Map;config;constructor(e,t){this.pathsObject=e,this.config=t}typeNameToFileName(e){return e=(e=(e=e.replace(/_/g,"-")).replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()).replace(/-+/g,"-")}propertiesParse(e){const s=[];for(const n in e){const r=e[n],a=this.schemaParse(r);let o="";o=Array.isArray(a)?`${t}${t}${n}:{${a.join("\n")}};`:`${t}${t}${n}:${a};`,s.push(o)}return s}nonArraySchemaObjectParse(e){if(!e)return"unknown";switch(e.type){case"boolean":return"boolean";case"integer":case"number":return"number";case"object":return this.propertiesParse(e.properties);case"string":return"string";default:return"unknown"}}arraySchemaObjectParse(e){if("array"!==e.type)return"";const{items:t}=e,s="$ref"in t?t:null,n=t;if(s){return`Array<${this.referenceObjectParse(s)}>`}if(n){const e=this.schemaParse(t);if(Array.isArray(e)){return`Array<{${e.join("\n")}}>`}return`Array<${e}>`}return""}referenceObjectParse(e){if(!e)return"";const t=e.$ref.replace("#/components/schemas/","");return`import('../models/${this.typeNameToFileName(t)}').${t}`}schemaParse(e){if(!e)return"unknown";const t=e?.type,s="$ref"in e?e:null,n="array"===t?e:null,r=t&&this.nonArrayType.includes(t)?e:null;return s?this.referenceObjectParse(s):n?this.arraySchemaObjectParse(n):r?this.nonArraySchemaObjectParse(r):"unknown"}responseObjectParse(e){const t=e.content;if(!t)return"";const{schema:s}=Object.values(t)[0];if(s){return this.schemaParse(s)}}responseHandle(e){const t=e[200];if(!t)return;const s="content"in t?t:null,n="$ref"in t?t:null;if(null===s&&null===n&&(this.contentBody.response="type Response = unknown",this.contentBody._response="unknown"),n){const e=this.referenceObjectParse(n);this.contentBody.response=`type Response = ${e}`,this.contentBody._response=e}if(s){const e=this.responseObjectParse(s);Array.isArray(e)?(this.contentBody.response=`interface Response {${e.join("\n")}} `,this.contentBody._response=`${e.join("\n")}`):(this.contentBody.response=`type Response = ${e}`,this.contentBody._response=`${e}`)}}requestBodyObjectParse(e){const s=Object.values(e.content),{schema:n}=Array.isArray(s)&&s.length>0?s[0]:{schema:null};if(n){const e=n?.type,s="$ref"in n?n:null,r="array"===e?n:null,a=e&&this.nonArrayType.includes(e)?n:null;if(s){const e=this.referenceObjectParse(s);return`${t}type Body = ${e}`}if(r){const e=this.arraySchemaObjectParse(r);return`${t}type Body = ${e}`}if(a){const e=this.nonArraySchemaObjectParse(a);return Array.isArray(e)?0===e.length?[`${t}type Body = unknown`]:[`${t}interface Body {`,...e,"}"]:[`${t}type Body = ${e}`]}}}requestBodyParse(e){if(!e)return"{}";const s="$ref"in e?e:null,n="content"in e?e:null;if(s){const e=this.referenceObjectParse(s);return`${t}type Body = ${e}`}return n&&"[object Object]"===String(e)&&0!==Reflect.ownKeys(e).length?this.requestBodyObjectParse(n):"{}"}requestParametersParse(e){const s=[],n=[];e?.map((e=>{const r="$ref"in e?e:null,a="name"in e?e:null;if(r){const e=this.referenceObjectParse(r);return console.log(this.pathKey,e,"item 是 ReferenceObject 类型","----未处理---"),e}if(a){if("path"===a.in){const e=this.schemaParse(a.schema);s.push(`${t}${t}type ${a.name} = ${e};`),this.contentBody.payload._path?"string"==typeof e?this.contentBody.payload._path[a.name]=e:console.log(e):"string"==typeof e?this.contentBody.payload._path={[a.name]:e}:console.log(e)}if("query"===a.in){const e=this.schemaParse(a.schema);n.push(`${t}${t}${a.name}: ${e};`),this.contentBody.payload._query?"string"==typeof e?this.contentBody.payload._query[a.name]=e:console.log(e):"string"==typeof e?this.contentBody.payload._query={[a.name]:e}:console.log(e)}}})),0!==s.length&&(s.unshift(`${t}namespace Path {`),s.push(`${t}}`)),0!==n.length&&(n.unshift(`${t}interface Query {`),n.push(`${t}}`)),this.contentBody.payload.path=s,this.contentBody.payload.query=n}requestHandle(e){if(e.parameters&&this.requestParametersParse(e.parameters),e.requestBody){const t=this.requestBodyParse(e.requestBody);if(Array.isArray(t))this.contentBody.payload.body=t;else if(t){const e=t?.split("\n")||[];this.contentBody.payload.body=e}}}parsePathItemObject(e,t){if(e)for(const s in e){const n=e[s];if(n){const e=s.toUpperCase(),r=t+"|"+e,{apiName:a,typeName:o,fileName:i,path:c}=this.convertEndpointString(r);this.contentBody.method=e,this.contentBody.typeName=o,this.contentBody.summary=n.summary,this.contentBody.fileName=i,this.contentBody.requestPath=c,this.contentBody.apiName=a,this.requestHandle(n),this.responseHandle(n.responses),this.Map.has(r)||this.Map.set(r,JSON.parse(JSON.stringify(this.contentBody))),this.contentBody={payload:{path:[],query:[],body:[]},response:"",_response:"",fileName:"",method:"",requestPath:"",summary:"",apiName:"",typeName:""}}}}convertEndpointString(e){let t=e;e.startsWith("/")||(t="/"+e);const[s,n]=t.split("|"),r=`${s.replace("/api/","").split("/").map((e=>e.includes("{")?`$${e.slice(1,-1)}`:e.charAt(0).toUpperCase()+e.slice(1))).join("")}_${n}`;return{apiName:r.charAt(0).toLowerCase()+r.slice(1),fileName:(s.slice(1).replace(/\//g,"-").replace("api-","")+"-"+n).toLowerCase(),typeName:r.charAt(0).toUpperCase()+r.slice(1),path:s.replace(/(\/api)|(api)/g,"").replace(/\{\w+\}/g,(e=>`$${e}`))}}apiRequestItemHandle(e){const{payload:t,requestPath:s,_response:n,method:r,typeName:a,apiName:o}=e,{_path:i,_query:c,body:p}=t,h=e=>{const t=[];for(const s in e)t.push(`${s}: ${a}.Path.${s}`);return t.length>1?t.join(","):t.join("")},y=i?h(i):"",l=c?`params: ${a}.Query`:"",u=p.length>0?`params: ${a}.Body`:"",m={};y&&(m.apiParamsPath=y),l&&(m.apiParamsQuery=l),u&&(m.apiParamsBody=u);const d=Object.keys(m).length>=2;return[`export const ${o} = `,"(",i?h(i):"",""+(d?",":""),c?`params: ${a}.Query`:"",p.length>0?`params: ${a}.Body`:"",")"," => ",`${r}${n?`<${a}.Response>`:""}`,"(`"+s+"`"+(l||u?", params":"")+");"].join("")}parseData(){return new Promise(((e,t)=>{try{for(const e in this.pathsObject){const t=this.pathsObject[e];t&&this.parsePathItemObject(t,e)}e(this.Map)}catch(e){t(e)}}))}writeFile(){const s=[],n=[],r=this.config.saveTypeFolderPath,a=[],o=(s,o)=>new Promise(((i,c)=>{try{const{payload:p,response:h,fileName:y,summary:l,typeName:u}=o,[,m]=s.split("|");!a.includes(m)&&a.push(m);const d=[`declare namespace ${u} {`,...p.path,...p.query,...p.body,`${t}${h}`,"}"],f=["/**","\n",` * ${l}`,"\n"," */"].join("");l&&n.push(f);const $=this.apiRequestItemHandle(o);n.push($,"\n"),e.writeFileRecursive(`${r}/api/${y}.d.ts`,d.join("\n")).then((()=>i(1))).catch((e=>{c(e),console.error(e)}))}catch(e){console.error(e,!0),c()}}));for(const[e,t]of this.Map)console.log(e),s.push(o(e,t));Promise.all(s).then((()=>{n.unshift(`import { ${a.join(", ")} } from '${this.config.requestMethodsImportPath||"./api"}';`,"\n"),e.clearDir(this.config.apiListFilePath+"/index.ts").finally((()=>{e.writeFileRecursive(this.config.apiListFilePath+"/index.ts",n.join("\n")).then((()=>{this.Map=new Map})).catch((e=>{console.error("-----------\x3e",e)}))}))}))}async handle(){await this.parseData(),await this.writeFile(),e.log.success("Path parse & write done!")}}exports.PathParse=r,exports.default=r;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../utils/index.js");const t="\t";var n;!function(e){e.GET="get",e.PUT="put",e.POST="post",e.DELETE="delete",e.OPTIONS="options",e.HEAD="head",e.PATCH="patch",e.TRACE="trace"}(n||(n={}));const r={typeMapping:new Map([["integer","number"],["string","string"],["boolean","boolean"],["binary","File"]]),errorHandling:{throwOnError:!1,logErrors:!0},formatting:{indentation:"\t",lineEnding:"\n"}};class s{pathsObject={};nonArrayType=["boolean","object","number","string","integer"];pathKey="";contentBody={payload:{path:[],query:[],body:[]},response:"",_response:"",fileName:"",method:"",requestPath:"",summary:"",apiName:"",typeName:""};Map=new Map;config;errors=[];schemaCache=new Map;referenceCache=new Map;templates={exportConst:e=>`export const ${e}`,typeDefinition:(e,t)=>`type ${e} = ${t}`,interfaceDefinition:e=>`interface ${e}`};constructor(e,t){this.pathsObject=e,this.config={...r,...t,typeMapping:new Map([...r.typeMapping||[],...t.typeMapping||[]])}}handleError(t){if(this.errors.push(t),this.config.errorHandling?.logErrors&&e.log.error(`${t.type}: ${t.message}${t.path?` at ${t.path}`:""}`),this.config.errorHandling?.throwOnError)throw new Error(`${t.type}: ${t.message}`)}getIndentation(){return this.config.formatting?.indentation||t}formatCode(e){const t=this.getIndentation(),n=this.config.formatting?.lineEnding||"\n";return e.split("\n").map((e=>`${t}${e}`)).join(n)}typeNameToFileName(e){return e=(e=(e=e.replace(/_/g,"-")).replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()).replace(/-+/g,"-")}handleComplexType(e){try{return e.oneOf?e.oneOf.map((e=>this.schemaParse(e))).join(" | "):e.allOf?e.allOf.map((e=>this.schemaParse(e))).join(" & "):e.anyOf?e.anyOf.map((e=>this.schemaParse(e))).join(" | "):e.enum?"number"===e.type||"integer"===e.type?e.enum.join(" | "):e.enum.map((e=>`'${e}'`)).join(" | "):"unknown"}catch(e){return this.handleError({type:"SCHEMA",message:"Failed to handle complex type",details:e}),"unknown"}}propertiesParse(e){const n=[];for(const r in e){const s=e[r],a=this.schemaParse(s);let o="";o=Array.isArray(a)?`${t}${t}${r}:{${a.join("\n")}};`:`${t}${t}${r}:${a};`,n.push(o)}return n}nonArraySchemaObjectParse(e){if(!e)return"unknown";switch(e.type){case"boolean":return"boolean";case"integer":case"number":return"number";case"object":return this.propertiesParse(e.properties);case"string":return"binary"===e.format?"File":"string";default:return"unknown"}}arraySchemaObjectParse(e){if("array"!==e.type)return"";const{items:t}=e,n="$ref"in t?t:null,r=t;if(n){return`Array<${this.referenceObjectParse(n)}>`}if(r){const e=this.schemaParse(t);return Array.isArray(e)?`Array<{${e.join("\n")}}>`:`Array<${e}>`}return""}referenceObjectParse(e){try{const t=e.$ref,n=this.referenceCache.get(t);if(n)return n;let r=t;t.startsWith("#/components/schemas/")?r=t.replace("#/components/schemas/",""):t.startsWith("#/definitions/")&&(r=t.replace("#/definitions/",""));const s=`import('../models/${this.typeNameToFileName(r)}').${r}`;return this.referenceCache.set(t,s),s}catch(e){return this.handleError({type:"REFERENCE",message:"Failed to parse reference object",details:e}),"unknown"}}schemaParse(e){try{if(!e)return"unknown";if("oneOf"in e||"allOf"in e||"anyOf"in e||"enum"in e)return this.handleComplexType(e);if("$ref"in e)return this.referenceObjectParse(e);const t=e,n=t.type,r=!0===t.nullable?" | null":"";if(n&&this.config.typeMapping?.has(n))return this.config.typeMapping.get(n)+r;if("array"===n&&t.items){return`Array<${this.schemaParse(t.items)}>`+r}if("object"===n){if(t.properties){const e=this.propertiesParse(t.properties);return e.length?e:["unknown"]}if(!0===t.additionalProperties)return"Record<string, unknown>"+r;if("object"==typeof t.additionalProperties){return`Record<string, ${this.schemaParse(t.additionalProperties)}>`+r}}return"unknown"}catch(e){return this.handleError({type:"SCHEMA",message:"Failed to parse schema",details:e}),"unknown"}}responseObjectParse(e){try{const t=e.content;if(!t)return"";const n=["application/json","text/json","text/plain","*/*"];let r;for(const e of n)if(t[e]?.schema){r=t[e].schema;break}return r?this.schemaParse(r):""}catch(e){return this.handleError({type:"RESPONSE",message:"Failed to parse response object",details:e}),""}}responseHandle(e){const t=e[200];if(!t)return;const n="content"in t?t:null,r="$ref"in t?t:null;if(null===n&&null===r&&(this.contentBody.response="type Response = unknown",this.contentBody._response="unknown"),r){const e=this.referenceObjectParse(r);this.contentBody.response=`type Response = ${e}`,this.contentBody._response=e}if(n){const e=this.responseObjectParse(n);Array.isArray(e)?(this.contentBody.response=`interface Response {${e.join("\n")}} `,this.contentBody._response=`${e.join("\n")}`):(this.contentBody.response=`type Response = ${e}`,this.contentBody._response=`${e}`)}}requestBodyObjectParse(e){const n=Object.values(e.content),{schema:r}=n[0]||{schema:null};if(r){const e=r?.type,n="$ref"in r?r:null,s="array"===e?r:null,a=e&&this.nonArrayType.includes(e)?r:null;if(n){const e=this.referenceObjectParse(n);return`${t}type Body = ${e}`}if(s){const e=this.arraySchemaObjectParse(s);return`${t}type Body = ${e}`}if(a){const e=this.nonArraySchemaObjectParse(a);return Array.isArray(e)?0===e.length?[`${t}type Body = unknown`]:[`${t}interface Body {`,...e,"}"]:[`${t}type Body = ${e}`]}}}requestBodyParse(e){if(!e)return"{}";const n="$ref"in e?e:null,r="content"in e?e:null;if(n){const e=this.referenceObjectParse(n);return`${t}type Body = ${e}`}return r&&"[object Object]"===String(e)&&0!==Reflect.ownKeys(e).length?this.requestBodyObjectParse(r):"{}"}requestParametersParse(n){const r=[],s=[];n?.map((n=>{const a="$ref"in n?n:null,o="name"in n?n:null;if(a){const t=this.referenceObjectParse(a);return e.log.warning(`${this.pathKey} ${t} item 是 ReferenceObject 类型 ----未处理---`),t}if(o){if("path"===o.in){const e=this.schemaParse(o.schema);r.push(`${t}${t}type ${o.name} = ${e};`),this.contentBody.payload._path?"string"==typeof e?this.contentBody.payload._path[o.name]=e:console.log("Unexpected v2value type:",e):"string"==typeof e?this.contentBody.payload._path={[o.name]:e}:console.log("Unexpected v2value type:",e)}if("query"===o.in){const e=this.schemaParse(o.schema);s.push(`${t}${t}${o.name}: ${e};`),this.contentBody.payload._query?"string"==typeof e?this.contentBody.payload._query[o.name]=e:console.log("Unexpected v2value type:",e):"string"==typeof e?this.contentBody.payload._query={[o.name]:e}:console.log("Unexpected v2value type:",e)}}})),0!==r.length&&(r.unshift(`${t}namespace Path {`),r.push(`${t}}`)),0!==s.length&&(s.unshift(`${t}interface Query {`),s.push(`${t}}`)),this.contentBody.payload.path=r,this.contentBody.payload.query=s}requestHandle(e){if(e.parameters&&this.requestParametersParse(e.parameters),e.requestBody){const t=this.requestBodyParse(e.requestBody);if(Array.isArray(t))this.contentBody.payload.body=t;else if(t){const e=t?.split("\n")||[];this.contentBody.payload.body=e}}}apiRequestItemHandle(e){const{payload:t,requestPath:n,_response:r,method:s,typeName:a,apiName:o}=e,{_path:i,_query:p,body:c}=t,h=c.some((e=>e.includes("File:")||e.includes(": File"))),l=e=>{const t=[];for(const n in e)t.push(`${n}: ${a}.Path.${n}`);return t.length>1?t.join(","):t.join("")},y=i?l(i):"",u=p?`params: ${a}.Query`:"",d=c.length>0?`params: ${a}.Body`:"",m={};y&&(m.apiParamsPath=y),u&&(m.apiParamsQuery=u),d&&(m.apiParamsBody=d);const f=Object.keys(m).length>=2,g=h?",'serve'":"",$=h?", { headers: { 'Content-Type': 'multipart/form-data' } }":"";return[`export const ${o} = `,"(",i?l(i):"",""+(f?",":""),p?`params: ${a}.Query`:"",c.length>0?`params: ${a}.Body`:"",")"," => ",`${s}${r?`<${a}.Response>`:""}`,"(`"+n+"`"+(u||d?", params":"")+g+$+");"].join("")}parsePathItemObject(e,t){if(e)for(const n in e){const r=e[n];if(r){const e=n.toUpperCase(),s=t+"|"+e,{apiName:a,typeName:o,fileName:i,path:p}=this.convertEndpointString(s);this.contentBody={payload:{path:[],query:[],body:[]},response:"",_response:"",fileName:i,method:e,typeName:o,requestPath:p,apiName:a,summary:r.summary},this.requestHandle(r),this.responseHandle(r.responses),this.Map.has(s)||this.Map.set(s,JSON.parse(JSON.stringify(this.contentBody)))}}}convertEndpointString(e){let t=e;e.startsWith("/")||(t="/"+e);const[n,r]=t.split("|"),s=`${n.replace("/api/","").split("/").map((e=>e.includes("{")?`$${e.slice(1,-1)}`:e.charAt(0).toUpperCase()+e.slice(1))).join("")}_${r}`;return{apiName:s.charAt(0).toLowerCase()+s.slice(1),fileName:(n.slice(1).replace(/\//g,"-").replace("api-","")+"-"+r).toLowerCase(),typeName:s.charAt(0).toUpperCase()+s.slice(1),path:n.replace(/(\/api)|(api)/g,"").replace(/\{\w+\}/g,(e=>`$${e}`))}}parseData(){return new Promise(((e,t)=>{try{for(const e in this.pathsObject){const t=this.pathsObject[e];t&&this.parsePathItemObject(t,e)}e(this.Map)}catch(e){this.handleError({type:"SCHEMA",message:"Failed to parse schema",details:e}),t(e)}}))}async writeFile(){const n=[],r=[],s=this.config.saveTypeFolderPath,a=[],o=(n,o)=>new Promise(((i,p)=>{try{const{payload:c,response:h,fileName:l,summary:y,typeName:u}=o,[,d]=n.split("|");!a.includes(d)&&a.push(d);const m=[`declare namespace ${u} {`,...c.path,...c.query,...c.body,`${t}${h}`,"}"];y&&r.push(["/**","\n",` * ${y}`,"\n"," */"].join(""));const f=this.apiRequestItemHandle(o);r.push(f,"\n"),e.writeFileRecursive(`${s}/api/${l}.d.ts`,m.join("\n")).then((()=>i(1))).catch((e=>{this.handleError({type:"FILE_WRITE",message:"Failed to write type definition file",path:l,details:e}),p(e)}))}catch(e){this.handleError({type:"PATH",message:"Failed to process path item",path:n,details:e}),p(e)}}));for(const[e,t]of this.Map)n.push(o(e,t));try{await Promise.all(n),r.unshift(`import { ${a.join(", ")} } from '${this.config.requestMethodsImportPath||"./api"}';`,"\n"),await e.clearDir(this.config.apiListFilePath+"/index.ts"),await e.writeFileRecursive(this.config.apiListFilePath+"/index.ts",r.join("\n")),this.Map=new Map,this.errors.length>0&&e.log.warning(`Completed with ${this.errors.length} errors`)}catch(e){throw this.handleError({type:"FILE_WRITE",message:"Failed to write API list file",details:e}),e}}async handle(){try{await this.parseData(),await this.writeFile(),e.log.success("Path parse & write done!")}catch(e){if(this.handleError({type:"SCHEMA",message:"Failed to handle schema",details:e}),this.config.errorHandling?.throwOnError)throw e}}}exports.PathParse=s,exports.default=s;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anl",
3
- "version": "1.3.25",
3
+ "version": "1.3.26",
4
4
  "description": "FE command line tool",
5
5
  "main": "bin/an-cli.js",
6
6
  "scripts": {