anl 1.3.15 → 1.3.17
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.15",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{
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../utils/index.js");const r="\t";exports.default=class{defaultReturn={headerRef:"",renderStr:""};schemas={};schemasMap=new Map;config;constructor(e,r){this.schemas=e,this.config=r}typeNameToFileName(e){return e.replace(/_/g,"-").replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase().replace(/-+/g,"-")}nameTheHumpCenterStroke(e){const r=e.replace("#/components/schemas/","");return{typeName:r,fileName:this.typeNameToFileName(r)}}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 a=e;if("object"==typeof a.additionalProperties){const e=this.parseArray(a.additionalProperties,r)??this.defaultReturn;t=e.headerRef,s=e.renderStr}}return{headerRef:t,renderStr:s}}parseArray(e,t){let s="",a="";const n=e;if(n.items?.$ref){const{headerRefStr:e,typeName:i}=this.parseRef(n.items.$ref);s=e,a=`${r}${t}?: Array<${i}>;`}else{const e=n.items;a=`${r}${t}?: Array<${"integer"===e.type?"number":e.type}>;`}return{headerRef:s,renderStr:a}}parseBoolean(e,t){return"boolean"===e.type?`${r}${t}?: boolean;`:""}parseEnum(e,t){if("integer"===e.type&&Array.isArray(e.enum)){return[`export enum ${t} {`,...e.enum.map((e=>`${r}NUMBER_${e} = ${e},`)),"}"].join("\n")}return""}parseInteger(e,t){return Array.isArray(e.enum)?this.parseEnum(e,t):`${r}${t}?: number;`}parseNumber(e,t){return"number"===e.type?`${r}${t}?: number;`:""}parseString(e,t){return"string"===e.type?{headerRef:"",renderStr:`${r}${t}?: string;`}:null}parseProperties(e,t){const s=[],a=[];for(const t in e){const n=e[t];if(n?.$ref){const{headerRefStr:e,typeName:i}=this.parseRef(n.$ref);a.includes(e)||a.push(e),s.push(`${r}${t}?: ${i};`)}else{if("allOf"in n){const e=n.allOf?.[0];if(e?.$ref){const{headerRefStr:n,typeName:i}=this.parseRef(e.$ref);a.includes(n)||a.push(n),s.push(`${r}${t}?: ${i};`);continue}}switch(n.type){case"array":{const e=this.parseArray(n,t)??this.defaultReturn;s.push(e.renderStr),a.includes(e.headerRef)||a.push(e.headerRef)}break;case"boolean":s.push(this.parseBoolean(n,t));break;case"integer":s.push(this.parseInteger(n,t));break;case"number":s.push(this.parseNumber(n,t));break;case"string":s.push(this.parseString(n,t)?.renderStr??"");break;case"object":{const{headerRef:e,renderStr:r}=this.parseObject(n,t)??this.defaultReturn;s.push(r),a.includes(e)||a.push(e)}}}}const n=`export interface ${t} {`;return[...a,"\n",n,...s,"}"].join("\n")}async parse(){for(const e in this.schemas){const r=this.schemas[e],t=r;if("$ref"in r){console.warn("ReferenceObject 未处理");continue}const s="type"in t?t:null,a=this.typeNameToFileName(e);if(s)if("items"in s)console.log("未处理---------------------------\x3e",s.items);else{let r="";switch(s.type){case"boolean":r=this.parseBoolean(s,e);break;case"integer":r=this.parseInteger(s,e);break;case"number":r=this.parseNumber(s,e);break;case"object":r=this.parseProperties(s.properties,e);break;case"string":r=this.parseString(s,e)?.renderStr??""}this.schemasMap.set(e,{fileName:a,content:r})}}}async writeFileHandler(){const r=[],t=[],s=`${this.config.saveTypeFolderPath}/models/`;for(const[,a]of this.schemasMap){const n=async({fileName:r,content:a})=>{t.push(`export * from './${r}';`),await e.writeFileRecursive(`${s}${r}.ts`,a)};r.push(n(a))}await Promise.all(r),await e.writeFileRecursive(`${s}/index.ts`,t.join("\n")),console.log("components done!")}async handle(){await this.parse(),await this.writeFileHandler()}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("fs"),t=require("../utils/index.js"),s=require("./core/components.js"),r=require("./core/get-data.js"),a=require("./core/path.js"),o=require("shelljs");function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("fs"),t=require("../utils/index.js"),s=require("./core/components.js"),r=require("./core/get-data.js"),a=require("./core/path.js"),o=require("shelljs");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=n(e);const l={saveTypeFolderPath:"apps/types",apiListFilePath:"apps/services",swaggerJsonUrl:"",requestMethodsImportPath:"./fetch",indent:"\t",headers:{}};exports.Main=class{schemas={};paths={};handle(e){return new Promise((t=>{if(!e.swaggerJsonUrl)return t({});r.getSwaggerJson(e).then((r=>{const o=r;this.schemas=o.components?.schemas,this.paths=o.paths;new s.default(this.schemas,e).handle();new a.PathParse(this.paths,e).handle(),t({})})).catch((()=>{t({})}))}))}initialize(){const e=process.cwd()+"/an.config.json";t.isFileExisted(e).then((()=>{i.default.readFile(e,"utf8",((e,s)=>{if(e)return void console.error(e);const r=JSON.parse(s);console.log("config ----\x3e",r),t.clearDir(r.saveTypeFolderPath).then((()=>{this.handle(r).then((e=>{console.log("format: ",`npx prettier --write "${r.saveTypeFolderPath}/**/*.{ts,d.ts}"`),o.exec(`npx prettier --write "${r.saveTypeFolderPath}/**/*.{ts,d.ts}"`)})).catch((e=>{console.log(e)}))}))}))})).catch((s=>{console.error("配置文件不存在,将自动创建配置文件!"),t.clearDir(l.saveTypeFolderPath).then((()=>{t.writeFileRecursive(e,JSON.stringify(l,null,2)).catch((e=>{console.log(e)})).finally((()=>{this.handle(l)}))}))}))}};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anl",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.17",
|
|
4
4
|
"description": "FE command line tool",
|
|
5
5
|
"main": "bin/an-cli.js",
|
|
6
6
|
"scripts": {
|
|
@@ -67,4 +67,4 @@
|
|
|
67
67
|
"url": "https://github.com/bianliuzhu/an-cli.git"
|
|
68
68
|
},
|
|
69
69
|
"type": "commonjs"
|
|
70
|
-
}
|
|
70
|
+
}
|