anl 1.2.0 → 1.2.2
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/LICENSE +1 -1
- package/README.md +0 -7
- package/lib/package.json.js +1 -1
- package/lib/src/build-type/core/path.js +1 -1
- package/lib/src/build-type/index.js +1 -1
- package/package.json +4 -8
package/LICENSE
CHANGED
package/README.md
CHANGED
package/lib/package.json.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e="1.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e="1.2.2",i="FE command line tool",s="bin/an-cli.js",l={dev:"rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript -w",build:"rm -rf lib && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",pub:"sh publish.sh",ts:"tsc ./src/int.ts --noEmit --watch"},p={anl:"bin/an-cli.js"},t="Gleason <bianliuzhu@gmail.com>",o={"@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",rollup:"^2.64.0","rollup-plugin-cleandir":"^2.0.0","rollup-plugin-terser":"^7.0.2",typescript:"^4.5.4","openapi-types":"^9.3.0"},r={"app-root-path":"^3.1.0",cac:"^6.7.12",chalk:"4.*","clear-console":"^1.1.0",commander:"^10.0.0",inquirer:"^9.1.4","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={name:"anl",version:e,description:i,main:s,scripts:l,bin:p,author:t,license:"ISC",devDependencies:o,dependencies:r,keywords:n,files:c,repository:u};exports.author=t,exports.bin=p,exports.default=a,exports.dependencies=r,exports.description=i,exports.devDependencies=o,exports.files=c,exports.keywords=n,exports.license="ISC",exports.main=s,exports.name="anl",exports.repository=u,exports.scripts=l,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={namespace:"",payload:{path:[],query:[],body:[]},response:"",_response:"",fileName:"",method:"",path:""};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}pathTranslantionName(e,t){return{name:e.slice(1).replace(/\/\{\w+\}/g,(()=>"")).replace(/\/\w/g,(e=>{const[,t]=e.split("");return t.toUpperCase()})).replace("api",""),method:t}}pathTranslantionFileName(e){const t=e.replace("/api","").replace(/\{\w+\}/g,(e=>`$${e}`));return{name:e.slice(1).replace(/\//g,"-").replace("api-",""),path:t}}typeNameToFileName(e){return e.replace(/([A-Z][a-z])/g,(e=>"-"+e.toLowerCase())).replace(/([A-Z]{2,})/g,"-$1").toLowerCase().slice(1)}propertiesParse(e){const s=[];for(const n in e){const r=e[n],a=this.schemaParse(r),o=`${t}${t}${n}:${a}`;s.push(o)}return s.join("\n")}nonArraySchemaObjectParse(e){if(!e)return"";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""}}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){return`Array<${this.schemaParse(t)}>`}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"";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):""}responseObjectParse(e){const t=e.content;if(!t)return"";const{schema:s}=Object.values(t)[0];if(s){return this.schemaParse(s).split("\n")}}responseHandle(e){const t=e[200],s="content"in t?t:null,n="$ref"in t?t:null;if(n){const e=this.referenceObjectParse(n);this.contentBody.response=`type Response = ${e}`,this.contentBody._response=e}if(s){const e=this.responseObjectParse(s);this.contentBody.response=`type Response = ${e}`,this.contentBody._response=`${e}`}}requestBodyObjectParse(e){const{schema:s}=Object.values(e.content)[0];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[`${t}interface 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?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?this.contentBody.payload._path[a.name]=e:this.contentBody.payload._path={[a.name]:e}}if("query"===a.in){const e=this.schemaParse(a.schema);n.push(`${t}${t}${a.name}: ${e};`),this.contentBody.payload._query?this.contentBody.payload._query[a.name]=e:this.contentBody.payload._query={[a.name]: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(t&&Array.isArray(t))this.contentBody.payload.body=t;else{const e=t?.split("\n")||[];this.contentBody.payload.body=e}}}parsePathItemObject(e){for(const t in s){const s=e[t.toLowerCase()];if(s){const{name:e,method:n}=this.pathTranslantionName(this.pathKey,t);this.requestHandle(s),this.responseHandle(s.responses),this.contentBody.method=n,this.contentBody.namespace=e+n}}}initialize(){return new Promise(((e,t)=>{try{for(const e in this.pathsObject){const t=this.pathsObject[e];if(this.pathKey=e,t){const s=this.pathTranslantionFileName(e);this.contentBody.fileName=s.name,this.contentBody.path=s.path,this.parsePathItemObject(t),this.Map.set(e,this.contentBody),this.contentBody={namespace:"",payload:{path:[],query:[],body:[]},response:"",_response:"",fileName:"",method:"",path:""}}}e(this.Map)}catch(e){t(e)}}))}writeApiListFile(e){const{namespace:t,payload:s,method:n,path:r,_response:a}=e,{_path:o,_query:i,body:c}=s,
|
|
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={namespace:"",payload:{path:[],query:[],body:[]},response:"",_response:"",fileName:"",method:"",path:""};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}pathTranslantionName(e,t){return{name:e.slice(1).replace(/\/\{\w+\}/g,(()=>"")).replace(/\/\w/g,(e=>{const[,t]=e.split("");return t.toUpperCase()})).replace("api",""),method:t}}pathTranslantionFileName(e){const t=e.replace("/api","").replace(/\{\w+\}/g,(e=>`$${e}`));return{name:e.slice(1).replace(/\//g,"-").replace("api-",""),path:t}}typeNameToFileName(e){return e.replace(/([A-Z][a-z])/g,(e=>"-"+e.toLowerCase())).replace(/([A-Z]{2,})/g,"-$1").toLowerCase().slice(1)}propertiesParse(e){const s=[];for(const n in e){const r=e[n],a=this.schemaParse(r),o=`${t}${t}${n}:${a}`;s.push(o)}return s.join("\n")}nonArraySchemaObjectParse(e){if(!e)return"";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""}}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){return`Array<${this.schemaParse(t)}>`}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"";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):""}responseObjectParse(e){const t=e.content;if(!t)return"";const{schema:s}=Object.values(t)[0];if(s){return this.schemaParse(s).split("\n")}}responseHandle(e){const t=e[200],s="content"in t?t:null,n="$ref"in t?t:null;if(null===s&&null===n&&(this.contentBody.response="type Response = void",this.contentBody._response="void"),n){const e=this.referenceObjectParse(n);this.contentBody.response=`type Response = ${e}['responseObject']`,this.contentBody._response=e}if(s){const e=this.responseObjectParse(s);this.contentBody.response=`type Response = ${e}['responseObject']`,this.contentBody._response=`${e}`}}requestBodyObjectParse(e){const{schema:s}=Object.values(e.content)[0];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[`${t}interface 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?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?this.contentBody.payload._path[a.name]=e:this.contentBody.payload._path={[a.name]:e}}if("query"===a.in){const e=this.schemaParse(a.schema);n.push(`${t}${t}${a.name}: ${e};`),this.contentBody.payload._query?this.contentBody.payload._query[a.name]=e:this.contentBody.payload._query={[a.name]: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(t&&Array.isArray(t))this.contentBody.payload.body=t;else{const e=t?.split("\n")||[];this.contentBody.payload.body=e}}}parsePathItemObject(e){for(const t in s){const s=e[t.toLowerCase()];if(s){const{name:e,method:n}=this.pathTranslantionName(this.pathKey,t);this.requestHandle(s),this.responseHandle(s.responses),this.contentBody.method=n,this.contentBody.namespace=e+n}}}initialize(){return new Promise(((e,t)=>{try{for(const e in this.pathsObject){const t=this.pathsObject[e];if(this.pathKey=e,t){const s=this.pathTranslantionFileName(e);this.contentBody.fileName=s.name,this.contentBody.path=s.path,this.parsePathItemObject(t),this.Map.set(e,this.contentBody),this.contentBody={namespace:"",payload:{path:[],query:[],body:[]},response:"",_response:"",fileName:"",method:"",path:""}}}e(this.Map)}catch(e){t(e)}}))}writeApiListFile(e){const{namespace:t,payload:s,method:n,path:r,_response:a}=e,{_path:o,_query:i,body:c}=s,p=t.replace(t[0],t[0].toLowerCase()),h=e=>{const s=[];for(const n in e)s.push(`${n}: ${t}.Path.${n}`);return s.length>1?s.join(","):s.join("")},l=o?h(o):"",y=i?`params: ${t}.Query`:"",u=c.length>0?`params: ${t}.Body`:"",d={};l&&(d.apiParamsPath=l),y&&(d.apiParamsQuery=y),u&&(d.apiParamsBody=u);const m=Object.keys(d).length>=2;return[`export const ${p} = `,"(",o?h(o):"",""+(m?",":""),i?`params: ${t}.Query`:"",c.length>0?`params: ${t}.Body`:"",")"," => ",`${n}${a?`<${t}.Response>`:""}`,"(`"+r+"`"+(y||u?", params":"")+")"].join("")}writeFileHabdler(){const s=[],n=[],r=this.config.saveTypeFolderPath,a=[],o=(s,o)=>new Promise(((s,i)=>{try{const{namespace:c,payload:p,response:h,fileName:l,method:y}=o;!a.includes(y)&&a.push(y);const u=[`declare namespace ${c} {`,...p.path,...p.query,...p.body,`${t}${h}`,"}"],d=this.writeApiListFile(o);n.push(d,"\n"),e.writeFileRecursive(`${r}/api/${l}.d.ts`,u.join("\n")).then((()=>s(1))).catch((e=>{i(e),console.error(e)}))}catch(e){console.error(e,!0),i()}}));for(const[e,t]of this.Map)s.push(o(0,t));Promise.all(s).then((()=>{n.unshift(`import { ${a.join(",")} } from './api';`,"\n"),e.clearDir(this.config.apiListFilePath+"/index.ts").finally((()=>{e.writeFileRecursive(this.config.apiListFilePath+"/index.ts",n.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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("fs"),s=require("../utils/index.js"),t=require("./core/components.js"),r=require("./core/get-data.js"),a=require("./core/path.js");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=n(e);const o={saveTypeFolderPath:"types",apiListFilePath:"services",swaggerJsonUrl:"
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("fs"),s=require("../utils/index.js"),t=require("./core/components.js"),r=require("./core/get-data.js"),a=require("./core/path.js");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=n(e);const o={saveTypeFolderPath:"apps/types",apiListFilePath:"apps/services",swaggerJsonUrl:"",indent:"\t",headers:{}};exports.Main=class{schemas={};paths={};handle(e){return new Promise((s=>{if(!e.swaggerJsonUrl)return s({});r.getSwaggerJson(e).then((r=>{const n=r;this.schemas=n.components?.schemas,this.paths=n.paths;new t.default(this.schemas,e).handle();new a.PathParse(this.paths,e).handle(),s({})})).catch((()=>{s({})}))}))}initialize(){const e=process.cwd()+"/an.config.json";s.isFileExisted(e).then((()=>{i.default.readFile(e,"utf8",((e,t)=>{if(e)return void console.error(e);const r=JSON.parse(t);console.log("config ----\x3e",r),s.clearDir(r.saveTypeFolderPath).then((()=>this.handle(r)))}))})).catch((t=>{s.clearDir(o.saveTypeFolderPath).then((()=>{s.writeFileRecursive(e,JSON.stringify(o,null,2)).catch((e=>{console.log(e)})).finally((()=>{this.handle(o)}))})),console.error(t)}))}};
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anl",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "FE command line tool",
|
|
5
5
|
"main": "bin/an-cli.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript -w",
|
|
8
8
|
"build": "rm -rf lib && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",
|
|
9
9
|
"pub": "sh publish.sh",
|
|
10
|
-
"ts": "
|
|
10
|
+
"ts": "tsc ./src/int.ts --noEmit --watch"
|
|
11
11
|
},
|
|
12
12
|
"bin": {
|
|
13
13
|
"anl": "bin/an-cli.js"
|
|
@@ -27,14 +27,13 @@
|
|
|
27
27
|
"@typescript-eslint/parser": "^5.52.0",
|
|
28
28
|
"eslint": "^8.7.0",
|
|
29
29
|
"husky": "^8.0.3",
|
|
30
|
-
"openapi-types": "^9.3.0",
|
|
31
30
|
"rollup": "^2.64.0",
|
|
32
31
|
"rollup-plugin-cleandir": "^2.0.0",
|
|
33
32
|
"rollup-plugin-terser": "^7.0.2",
|
|
34
|
-
"typescript": "^4.5.4"
|
|
33
|
+
"typescript": "^4.5.4",
|
|
34
|
+
"openapi-types": "^9.3.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@rollup/plugin-alias": "^5.1.0",
|
|
38
37
|
"app-root-path": "^3.1.0",
|
|
39
38
|
"cac": "^6.7.12",
|
|
40
39
|
"chalk": "4.*",
|
|
@@ -63,8 +62,5 @@
|
|
|
63
62
|
"repository": {
|
|
64
63
|
"type": "git",
|
|
65
64
|
"url": "https://github.com/bianliuzhu/an-cli.git"
|
|
66
|
-
},
|
|
67
|
-
"volta": {
|
|
68
|
-
"node": "18.19.1"
|
|
69
65
|
}
|
|
70
66
|
}
|