anl 1.3.13 → 1.3.15
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/lib/package.json.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e="1.3.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e="1.3.14",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",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 r="\t";exports.default=class{defalutReturn={headerRef:"",renderStr:""};schemas={};schemasMap=new Map;config;constructor(e,r){this.schemas=e,this.config=r}typeNameToFileName(e){return e.replace(/
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../utils/index.js");const r="\t";exports.default=class{defalutReturn={headerRef:"",renderStr:""};schemas={};schemasMap=new Map;config;constructor(e,r){this.schemas=e,this.config=r}typeNameToFileName(e){return e=(e=(e=e.replace(/_/g,"-")).replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()).replace(/-+/g,"-")}nameTheHumpCenterStroke(e){try{const r=e.replace("#/components/schemas/","");return{typeName:r,fileName:this.typeNameToFileName(r)}}catch(e){throw console.error(e),JSON.stringify(e)}}parseRef(e){if(!e)return{headerRefStr:"",typeName:""};const{fileName:r,typeName:t}=this.nameTheHumpCenterStroke(e);return{headerRefStr:`import { ${t} } from './${r}';`,typeName:t}}parseObject(e,r){let t="",s="";if("object"===e.type){const n=e;switch(typeof n.additionalProperties){case"boolean":return{headerRef:"",renderStr:""};case"object":{const e=this.parseArray(n.additionalProperties,r)??this.defalutReturn,{headerRef:a,renderStr:i}=e;t=a,s=i}}}return{headerRef:t,renderStr:s}}parseArray(e,t){let s="",n="";const a=e.items.$ref;if(a){const{headerRefStr:i,typeName:o}=this.parseRef(a);s=i;n=`${r}${t}${e?.nullable?"?:":":"} Array<${o}>;`}else{const s=e,a=s?.items;n=`${r}${t}${e?.nullable?"?:":":"} Array<${"integer"===a?.type?"number":a?.type}>;`}return{headerRef:s,renderStr:n}}parseBoolean(e,t){if("boolean"!==e.type)return"";return`${r}${t}: boolean;`}parseEnum(e,t){if("integer"!==e.type)return"";if(Array.isArray(e.enum)){return[`export enum ${t} {`,...e.enum.map((e=>`${r}NUMBER_${e} = ${e},`)),"}"].join("\n")}return""}parseInteger(e,t){return"integer"!==e.type?"":Array.isArray(e.enum)?this.parseEnum(e,t):`${r}${t}: number;`}parseNumber(e,t){if("number"!==e.type)return"";return`${r}${t}: number;`}parseString(e,t){if("string"!==e.type)return null;return{headerRef:"",renderStr:`${r}${t}: string;`}}parseProperties(e,t){try{const s=[],n=[];for(const t in e){const a=e[t];if(a.$ref){const{headerRefStr:e,typeName:i}=this.parseRef(a.$ref);!n.includes(e)&&n.push(e),s.push(`${r}${t}: ${i};`)}else{if("allOf"in a){const e=a.allOf?.[0];if(e?.$ref){const{headerRefStr:a,typeName:i}=this.parseRef(e.$ref);!n.includes(a)&&n.push(a),s.push(`${r}${t}: ${i};`);continue}}switch(a.type){case"array":{const e=this.parseArray(a,t)??this.defalutReturn,{headerRef:r,renderStr:i}=e;s.push(i),!n.includes(r)&&n.push(r)}break;case"boolean":{const e=this.parseBoolean(a,t)??this.defalutReturn;s.push(e)}break;case"integer":{const e=this.parseInteger(a,t)??this.defalutReturn;s.push(e)}break;case"number":{const e=this.parseNumber(a,t)??this.defalutReturn;s.push(e)}break;case"string":{const{renderStr:e}=this.parseString(a,t)??this.defalutReturn;s.push(e)}break;case"object":{const{headerRef:e,renderStr:r}=this.parseObject(a,t)??this.defalutReturn;s.push(r),!n.includes(e)&&n.push(e)}}}}const a=`export interface ${t} {`;return[...n,"\n",a,...s,"}"].join("\n")}catch(e){throw console.error(e),JSON.stringify(e)}}parse(){return new Promise(((e,r)=>{try{for(const e in this.schemas){const r=this.schemas[e],t="type"in r?r:null;if(("$ref"in r?r:null)&&console.warn("ReferenceObject 未处理"),t){const t="items"in r?r:r,s=this.typeNameToFileName(e);if("items"in t)console.log("未处理---------------------------\x3e",t.items);else switch(t.type){case"boolean":{const r=this.parseBoolean(t,e)??this.defalutReturn;this.schemasMap.set(e,{fileName:s,content:r})}break;case"integer":{const r=this.parseInteger(t,e);this.schemasMap.set(e,{fileName:s,content:r})}break;case"number":{const r=this.parseNumber(t,e);this.schemasMap.set(e,{fileName:s,content:r})}break;case"object":{const r=this.parseProperties(t.properties,e);this.schemasMap.set(e,{fileName:s,content:r})}break;case"string":{const{renderStr:r}=this.parseString(t,e)??this.defalutReturn;this.schemasMap.set(e,{fileName:s,content:r})}}}}e(!0)}catch(e){console.error(e),r(e)}}))}writeFileHabdler(){const r=[],t=[],s=`${this.config.saveTypeFolderPath}/models/`,n=({fileName:r,content:n})=>new Promise(((a,i)=>{try{t.push(`export * from './${r}';`),e.writeFileRecursive(`${s}${r}.ts`,n).finally((()=>a(void 0)))}catch(e){console.error(e,!0),i()}}));for(const[,e]of this.schemasMap)r.push(n(e));Promise.all(r).then((()=>{e.writeFileRecursive(`${s}/index.ts`,t.join("\n")).finally((()=>console.log("components done!")))}))}handle(){this.parse().then((()=>this.writeFileHabdler()))}};
|
|
@@ -1 +1 @@
|
|
|
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 s={payload:{path:[],query:[],body:[]},response:"",_response:"",fileName:"",apiName:"",typeName:"",method:"",requestPath:"",summary:""};class r{pathsObject={};nonArrayType=["boolean","object","number","string","integer"];pathKey="";contentBody=s;Map=new Map;config;constructor(e,t){this.pathsObject=e,this.config=t}typeNameToFileName(e){return e.replace(/
|
|
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 s={payload:{path:[],query:[],body:[]},response:"",_response:"",fileName:"",apiName:"",typeName:"",method:"",requestPath:"",summary:""};class r{pathsObject={};nonArrayType=["boolean","object","number","string","integer"];pathKey="";contentBody=s;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 n=[];for(const s in e){const r=e[s],a=this.schemaParse(r);let o="";o=Array.isArray(a)?`${t}${t}${s}:{${a.join("\n")}};`:`${t}${t}${s}:${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"string";default:return"unknown"}}arraySchemaObjectParse(e){if("array"!==e.type)return"";const{items:t}=e,n="$ref"in t?t:null,s=t;if(n){return`Array<${this.referenceObjectParse(n)}>`}if(s){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,n="$ref"in e?e:null,s="array"===t?e:null,r=t&&this.nonArrayType.includes(t)?e:null;return n?this.referenceObjectParse(n):s?this.arraySchemaObjectParse(s):r?this.nonArraySchemaObjectParse(r):"unknown"}responseObjectParse(e){const t=e.content;if(!t)return"";const{schema:n}=Object.values(t)[0];if(n){return this.schemaParse(n)}}responseHandle(e){const t=e[200];if(!t)return;const n="content"in t?t:null,s="$ref"in t?t:null;if(null===n&&null===s&&(this.contentBody.response="type Response = unknown",this.contentBody._response="unknown"),s){const e=this.referenceObjectParse(s);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:s}=Array.isArray(n)&&n.length>0?n[0]:{schema:null};if(s){const e=s?.type,n="$ref"in s?s:null,r="array"===e?s:null,a=e&&this.nonArrayType.includes(e)?s:null;if(n){const e=this.referenceObjectParse(n);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 n="$ref"in e?e:null,s="content"in e?e:null;if(n){const e=this.referenceObjectParse(n);return`${t}type Body = ${e}`}return s&&"[object Object]"===String(e)&&0!==Reflect.ownKeys(e).length?this.requestBodyObjectParse(s):"{}"}requestParametersParse(e){const n=[],s=[];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);n.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);s.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!==n.length&&(n.unshift(`${t}namespace Path {`),n.push(`${t}}`)),0!==s.length&&(s.unshift(`${t}interface Query {`),s.push(`${t}}`)),this.contentBody.payload.path=n,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}}}parsePathItemObject(e,t){if(e)for(const n in e){const s=e[n];if(s){const e=n.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=s.summary,this.contentBody.fileName=i,this.contentBody.requestPath=c,this.contentBody.apiName=a,this.requestHandle(s),this.responseHandle(s.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:""}}}}initialize(){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)}}))}convertEndpointString(e){let t=e;e.startsWith("/")||(t="/"+e);const[n,s]=t.split("|"),r=`${n.replace("/api/","").split("/").map((e=>e.includes("{")?`$${e.slice(1,-1)}`:e.charAt(0).toUpperCase()+e.slice(1))).join("")}_${s}`;return{apiName:r.charAt(0).toLowerCase()+r.slice(1),fileName:(n.slice(1).replace(/\//g,"-").replace("api-","")+"-"+s).toLowerCase(),typeName:r.charAt(0).toUpperCase()+r.slice(1),path:n.replace(/(\/api)|(api)/g,"").replace(/\{\w+\}/g,(e=>`$${e}`))}}apiRequestItemHandle(e){const{payload:t,requestPath:n,_response:s,method:r,typeName:a,apiName:o}=e,{_path:i,_query:c,body:p}=t,h=e=>{const t=[];for(const n in e)t.push(`${n}: ${a}.Path.${n}`);return t.length>1?t.join(","):t.join("")},y=i?h(i):"",l=c?`params: ${a}.Query`:"",u=p.length>0?`params: ${a}.Body`:"",d={};y&&(d.apiParamsPath=y),l&&(d.apiParamsQuery=l),u&&(d.apiParamsBody=u);const m=Object.keys(d).length>=2;return[`export const ${o} = `,"(",i?h(i):"",""+(m?",":""),c?`params: ${a}.Query`:"",p.length>0?`params: ${a}.Body`:"",")"," => ",`${r}${s?`<${a}.Response>`:""}`,"(`"+n+"`"+(l||u?", params":"")+");"].join("")}writeFileHabdler(){const n=[],s=[],r=this.config.saveTypeFolderPath,a=[],o=(n,o)=>new Promise(((i,c)=>{try{const{payload:p,response:h,fileName:y,summary:l,typeName:u}=o,[,d]=n.split("|");!a.includes(d)&&a.push(d);const m=[`declare namespace ${u} {`,...p.path,...p.query,...p.body,`${t}${h}`,"}"],f=["/**","\n",` * ${l}`,"\n"," */"].join("");l&&s.push(f);const $=this.apiRequestItemHandle(o);s.push($,"\n"),e.writeFileRecursive(`${r}/api/${y}.d.ts`,m.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),n.push(o(e,t));Promise.all(n).then((()=>{s.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",s.join("\n")).then((()=>{console.log("path parse done!"),this.Map=new Map})).catch((e=>{console.error("-----------\x3e",e)}))}))}))}handle(){this.initialize().then((()=>this.writeFileHabdler()))}}exports.PathParse=r,exports.default=r;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anl",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.15",
|
|
4
4
|
"description": "FE command line tool",
|
|
5
5
|
"main": "bin/an-cli.js",
|
|
6
6
|
"scripts": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@typescript-eslint/parser": "^5.52.0",
|
|
28
28
|
"eslint": "^8.7.0",
|
|
29
29
|
"husky": "^8.0.3",
|
|
30
|
-
"openapi-types": "^
|
|
30
|
+
"openapi-types": "^12.1.3",
|
|
31
31
|
"prettier": "^3.3.2",
|
|
32
32
|
"rimraf": "^5.0.7",
|
|
33
33
|
"rollup": "^2.64.0",
|
|
@@ -67,4 +67,4 @@
|
|
|
67
67
|
"url": "https://github.com/bianliuzhu/an-cli.git"
|
|
68
68
|
},
|
|
69
69
|
"type": "commonjs"
|
|
70
|
-
}
|
|
70
|
+
}
|