sy-api-pro 0.0.10 → 0.1.1

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/dist/index.umd.js CHANGED
@@ -1,13 +1,13 @@
1
- var R=(j,y,m)=>new Promise((D,B)=>{var a=g=>{try{n(m.next(g))}catch(b){B(b)}},d=g=>{try{n(m.throw(g))}catch(b){B(b)}},n=g=>g.done?D(g.value):Promise.resolve(g.value).then(a,d);n((m=m.apply(j,y)).next())});(function(j,y){typeof exports=="object"&&typeof module!="undefined"?y(require("axios")):typeof define=="function"&&define.amd?define(["axios"],y):y((j=typeof globalThis!="undefined"?globalThis:j||self).axios)})(this,function(j){"use strict";function y(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var m=y(j);const D=e=>{var r;const o=(e||"").toLowerCase(),h={int:"number",integer:"number",long:"number",bigdecimal:"number",float:"number",double:"number",localdatetime:"string",date:"string",char:"string",byte:"string",short:"string",character:"string",string:"string",multipartfile:"string",boolean:"boolean",void:"void"},{listType:i}=((r=/^list<(?<listType>.+)>$/.exec(o))==null?void 0:r.groups)||{};return i?`Array<${h[i]||"any"}>`:h[o]||"any"},B=Object.freeze({_getDesc(e){const o=(e.title||"").trim();return o?` // ${o}`:""},getInterface:function({list:e,config:{ignoreParamsDTO:o,deleteParentDTO:h}}){const i=e.filter(r=>!r.id);return e.filter(r=>r.id&&!o.includes(r.type)).map(r=>{if(r.id&&r.json){const p=r.json.split(`
2
- `);return p.forEach((t,s)=>{var f;const l=/(?<space>\s*)"(?<name>[a-zA-Z0-9]+)"\s?:\s*"(?<desc>.*)".*$/;if(l.test(t)){const{space:I,name:w,desc:F}=((f=l.exec(t))==null?void 0:f.groups)||{},O=(w||"").trim(),x=(F||"").trim(),P=i.filter(c=>(c.name||"").trim()+(c.title||"").trim()===O+x);if(P.length>=1){const[{type:c}]=P,$=r.required?"?":"";p[s]=t.replace(l,`${I+w+$}: ${D(c)};${x?` // ${x}`:""}`)}}/\s*"[a-zA-Z0-9]+"\s*:\s*.+$/.test(t)&&(p[s]=p[s].replace(/(\s*)"([a-zA-Z0-9]+)"\s?(:\s*.+)$/,"$1$2$3")),p[s]=p[s].replace(/(.*)\[\s+{$/,"$1Array<{").replace(/(.*)}\s*].*$/,"$1}>")}),h.some(t=>{const s=Object.prototype.toString.call(t);return s==="[object RegExp]"?t.test(r.type):s==="[object String]"?t===r.type:void 0})?p.slice(1,-1).join(`
3
- `):[` ${r.name}${r.required?"":"?"}: {${this._getDesc(r)}`,...p.slice(1,-1).map(t=>` ${t}`)," }"].join(`
4
- `)}return` ${r.name}${r.required?"":"?"}: ${D(r.type)};${this._getDesc(r)}`})}}),a=require("fs"),d=require("path"),n=require("chalk");m.default.interceptors.response.use(e=>{var o,h;return((h=(o=e.data)==null?void 0:o.head)==null?void 0:h.successful)?e:Promise.reject(e)},e=>{throw e});const g=require("path"),{program:b}=require("commander"),M=require("chalk");b.version(require(g.resolve(__dirname,"../package.json")).version).requiredOption("-i, --id <id>","methodId").option("-n, --name <name>","customMethodName").requiredOption("--config <filePath>","configFilePath").requiredOption("--project-id <id>","projectId").parse();const{id:A,name:L,config:T,projectId:N}=b.opts();if(!A||!/^\d+$/.test(A))throw M.red("\u3010error\u3011\u8BF7\u4F20\u5165\u6B63\u786E\u7684 id");const S=require(g.resolve(process.cwd(),T)),u=(S.projects||[]).find(e=>+e.projectId==+N);if(u){if(!u.branchId)throw M.red("\u3010error\u3011\u8BF7\u4F20\u5165\u6B63\u786E\u7684 branchId");if(!S.api)throw M.red("\u3010error\u3011\u8BF7\u4F20\u5165\u6B63\u786E\u7684 api");new class{constructor(e){this.config={api:"",creatBaseFile:!0,customMethodName:"",projectId:void 0,branchId:void 0,methodId:void 0,outputPath:"",outputDirName:"",apiBaseName:"",ignoreParamsDTO:[],deleteParentDTO:[]},this.apiList=[],this.enums=[],Object.assign(this.config,e),this.getApiData()}getApiData(){return R(this,null,function*(){const{api:e,branchId:o,projectId:h,outputDirName:i,outputPath:r,methodId:p,creatBaseFile:t}=this.config;try{const{data:s}=yield m.default.get(`${e}/api/project/getProjectWithBranchById?id=${h}`);this.config.outputPath=d.join(process.cwd(),r,i||s.body.name);const l=s.body.branchList.find(I=>I.id===o);if(!l)throw n.red(`\u3010error\u3011branchId ${o} \u4E0D\u5B58\u5728`);console.log(n.blueBright(`\u3010info\u3011\u6B63\u5728\u4F7F\u7528 branchName: ${l.name} branchId: ${o} methodId: ${p}`));const f=yield m.default.get(`${e}/api/method/getMethodById?id=${p}`);this.apiList=[f.data.body]}catch(s){return console.log(n.red("\u3010error\u3011: \u63A5\u53E3\u83B7\u53D6\u5F02\u5E38")),void console.log(s)}try{yield this.checkApiOutputDir()}catch(s){return console.log(n.red("\u3010error\u3011: \u68C0\u67E5\u8F93\u51FA\u76EE\u5F55\u5F02\u5E38")),void console.log(s)}t&&(yield this.creatBaseFile());try{yield this.createFile()}catch(s){console.log(n.red("\u3010error\u3011: createFile \u5F02\u5E38")),console.log(s)}})}checkApiOutputDir(){const{outputPath:e}=this.config;console.log(n.blueBright(`\u3010info\u3011\u8F93\u51FA\u76EE\u5F55 ${e}`));try{a.statSync(e,{bigint:!0})}catch(o){a.mkdirSync(e,{recursive:!0})}}creatBaseFile(){return R(this,null,function*(){const{outputPath:e}=this.config,o=d.join(__dirname,"../template"),h=a.readdirSync(o),i=a.readdirSync(e);for(const r of h)if(!i.includes(r))try{const p=a.readFileSync(d.join(o,r));a.writeFileSync(d.join(e,r),p)}catch(p){console.log(n.red("\u3010error\u3011: \u57FA\u7840\u6587\u4EF6\u751F\u6210\u5F02\u5E38")),console.log(p)}})}createFile(){return R(this,null,function*(){const{apiBaseName:e,outputPath:o,customMethodName:h}=this.config;this.apiList.forEach(i=>{var O,x,P;const r=c=>c.replace(/(-[a-z])|(^[a-z])/g,$=>$.replace("-","").toLocaleUpperCase()),p=new RegExp(`(${e})?(/)?(?<apiDirName>[a-zA-Z0-9_]+)/.*$`),{apiDirName:t}=((O=p.exec(i.path))==null?void 0:O.groups)||{},s=h||i.name,l=r(`${t}-`+s);try{a.statSync(d.join(o,t)).isDirectory()}catch(c){a.mkdirSync(d.join(o,t))}const f=(x=i.paramList)==null?void 0:x.length;let I=[],w=[];try{I=["/**************************************************/",...f?[`/** ${i.title} RequestModel */`,`export interface ${l}ReqModel {`,...B.getInterface({list:i.paramList||[],config:this.config}),"}",""]:[],""],w=[...((P=i.returnList)==null?void 0:P.length)?[`/** ${i.title} ResponseModel */`,`export interface ${l}ResModel {`,...B.getInterface({list:i.returnList||[],config:this.config}),"}"]:[],""]}catch(c){throw console.log(n.red(`\u3010error\u3011\u7C7B\u578B\u751F\u6210\u5931\u8D25 projectId: ${this.config.projectId} methodId: ${i.id} path: ${i.path}`)),n.red(c)}try{const c=a.readFileSync(d.join(o,t,"models.ts")).toString();c.includes(`export interface ${l}ReqModel {`)?console.log(n.yellowBright(`\u3010warning\u3011./${t}/models.ts \u5DF2\u5B58\u5728 ${l}ReqModel`)):(a.appendFileSync(d.join(o,`./${t}/models.ts`),[""].concat(I).join(`
5
- `)),console.log(n.greenBright(`\u3010success\u3011./${t}/models.ts \u6210\u529F\u6DFB\u52A0 ${l}ReqModel`))),c.includes(`export interface ${l}ResModel {`)?console.log(n.yellowBright(`\u3010warning\u3011./${t}/models.ts \u5DF2\u5B58\u5728 ${l}ResModel`)):(a.appendFileSync(d.join(o,`./${t}/models.ts`),[""].concat(w).join(`
6
- `)),console.log(n.greenBright(`\u3010success\u3011./${t}/models.ts \u6210\u529F\u6DFB\u52A0 ${l}ResModel`)))}catch(c){a.writeFileSync(d.join(o,`./${t}/models.ts`),w.join(`
7
- `)),console.log(n.greenBright(`\u3010success\u3011./${t}/models.ts \u6210\u529F\u6DFB\u52A0 ${l}ReqModel`))}const F=[i.title&&` /** ${i.title} */`,` ${s}(${f?`params: M.${l}ReqModel`:""}) {`,` return axios.${i.method.toLowerCase()}<ApiResponse<M.${l}ResModel>>(`,` \`\${ApiPrefix}/${i.path}\`,`,f&&` ${["post","put","patch"].includes(i.method.toLowerCase())?"params":"{ params }"},`," );"," },"].filter(Boolean);/^[a-zA-Z]+$/.test((i.method||"").trim())||console.log(n.yellowBright(`\u3010warning\u3011\u63A5\u53E3\u8BF7\u6C42\u7C7B\u578B\u5F02\u5E38\uFF0C\u8BF7\u624B\u52A8\u8865\u5168 method\uFF1A${i.method} path: ${i.path} methodId: ${this.config.methodId} projectId: ${this.config.projectId}`));try{const c=a.readFileSync(d.join(o,t,"api.ts")).toString();if(c.includes(` ${s}(`))console.log(n.yellowBright(`\u3010warning\u3011./${t}/api.ts \u5DF2\u5B58\u5728 ${s}`));else{const $=c.split(`
8
- `);$.splice($.map(q=>q.includes("}")).lastIndexOf(!0),0,F.join(`
9
- `)),a.writeFileSync(d.join(o,`./${t}/api.ts`),$.join(`
10
- `)),console.log(n.greenBright(`\u3010success\u3011./${t}/api.ts \u6210\u529F\u6DFB\u52A0 ${s}`))}}catch($){a.writeFileSync(d.join(o,`./${t}/api.ts`),["import axios from 'axios';","","import * as M from './models';","import { ApiResponse } from '../responseModel';","import { ApiPrefix } from '../apiPrefix';","","export * from './models';","",`export const ${r(t)}Api = {`,...F,"};",""].join(`
11
- `)),console.log(n.greenBright(`\u3010success\u3011./${t}/api.ts \u6210\u529F\u6DFB\u52A0 ${s}`));const c=a.readFileSync(d.join(o,"index.ts")).toString();if(!c.includes(`export * from './${t}/api'`)){const q=c.split(`
12
- `);q.push(`export * from './${t}/api';`);const v=q.slice(1).filter(Boolean);v.sort((z,_)=>z.localeCompare(_)),a.writeFileSync(d.join(o,"index.ts"),[q[0]||"","",...v,""].join(`
13
- `))}}})})}}({api:S.api,creatBaseFile:u.creatBaseFile||!0,methodId:A,customMethodName:L,outputPath:S.outputPath||"./src/apis",projectId:u.projectId,branchId:+u.branchId,outputDirName:u.outputDirName||"",apiBaseName:u.apiBaseName||"",ignoreParamsDTO:u.ignoreParamsDTO||[],deleteParentDTO:u.deleteParentDTO||[]})}else console.log(M.red(`\u3010error\u3011config \u914D\u7F6E\u6587\u4EF6\u4E2D projects \u672A\u5305\u542B\u4F20\u5165\u7684 projectId ${N}`))});
1
+ var L=(B,D,y)=>new Promise((P,x)=>{var c=f=>{try{u(y.next(f))}catch(m){x(m)}},p=f=>{try{u(y.throw(f))}catch(m){x(m)}},u=f=>f.done?P(f.value):Promise.resolve(f.value).then(c,p);u((y=y.apply(B,D)).next())});(function(B,D){typeof exports=="object"&&typeof module!="undefined"?D(require("axios")):typeof define=="function"&&define.amd?define(["axios"],D):(B=typeof globalThis!="undefined"?globalThis:B||self,D(B.axios))})(this,function(B){"use strict";function D(r){return r&&typeof r=="object"&&"default"in r?r:{default:r}}var y=D(B);const P=r=>{var e;const n=(r||"").toLowerCase(),i={int:"number",integer:"number",long:"number",bigdecimal:"number",float:"number",double:"number",localdatetime:"string",date:"string",char:"string",byte:"string",short:"string",character:"string",string:"string",multipartfile:"string",boolean:"boolean",void:"void"},{listType:l}=((e=/^list<(?<listType>.+)>$/.exec(n))==null?void 0:e.groups)||{};return l?`Array<${i[l]||"any"}>`:i[n]||"any"},x=Object.freeze({_getDesc(r){const n=(r.title||"").trim();return n?` // ${n}`:""},getInterface:function({list:r,config:{ignoreParamsDTO:n,deleteParentDTO:i}}){const l=r.filter(e=>!e.id);return r.filter(e=>e.id&&!n.includes(e.type)).map(e=>{if(e.id&&e.json){const s=e.json.split(`
2
+ `);return s.forEach((t,o)=>{var $;const a=/(?<space>\s*)"(?<name>[a-zA-Z0-9]+)"\s?:\s*"(?<desc>.*)".*$/;if(a.test(t)){const{space:g,name:w,desc:_}=(($=a.exec(t))==null?void 0:$.groups)||{},C=(w||"").trim(),b=(_||"").trim(),q=l.filter(I=>(I.name||"").trim()+(I.title||"").trim()===C+b);if(q.length>=1){const[{type:I}]=q,R=e.required?"?":"";s[o]=t.replace(a,`${g+w+R}: ${P(I)};${b?` // ${b}`:""}`)}}/\s*"[a-zA-Z0-9]+"\s*:\s*.+$/.test(t)&&(s[o]=s[o].replace(/(\s*)"([a-zA-Z0-9]+)"\s?(:\s*.+)$/,"$1$2$3")),s[o]=s[o].replace(/(.*)\[\s+{$/,"$1Array<{").replace(/(.*)}\s*].*$/,"$1}>")}),i.some(t=>{const o=Object.prototype.toString.call(t);if(o==="[object RegExp]")return t.test(e.type);if(o==="[object String]")return t===e.type})?s.slice(1,-1).join(`
3
+ `):[` ${e.name}${e.required?"":"?"}: {${this._getDesc(e)}`,...s.slice(1,-1).map(t=>` ${t}`)," }"].join(`
4
+ `)}else return` ${e.name}${e.required?"":"?"}: ${P(e.type)};${this._getDesc(e)}`})}}),c=require("fs"),p=require("path"),u=require("chalk");y.default.interceptors.response.use(r=>{var n,i;return(i=(n=r.data)==null?void 0:n.head)!=null&&i.successful?r:Promise.reject(r)},r=>{throw r});const f=class{constructor(n){this.config={api:"",creatBaseFile:!0,customMethodName:"",projectId:void 0,branchId:void 0,methodId:void 0,outputPath:"",outputDirName:"",apiBaseName:"",ignoreParamsDTO:[],deleteParentDTO:[]},this.apiList=[],this.enums=[],Object.assign(this.config,n),this.getApiData()}getApiData(){return L(this,null,function*(){const{api:n,branchId:i,projectId:l,outputDirName:e,outputPath:s,methodId:d,creatBaseFile:t}=this.config;try{const{data:o}=yield y.default.get(`${n}/api/project/getProjectWithBranchById?id=${l}`);this.config.outputPath=p.join(process.cwd(),s,e||o.body.name);const a=o.body.branchList.find(g=>g.id===i);if(a)console.log(u.blueBright(`\u3010info\u3011\u6B63\u5728\u4F7F\u7528 branchName: ${a.name} branchId: ${i} methodId: ${d}`));else throw u.red(`\u3010error\u3011branchId ${i} \u4E0D\u5B58\u5728`);const $=yield y.default.get(`${n}/api/method/getMethodById?id=${d}`);this.apiList=[$.data.body]}catch(o){console.log(u.red("\u3010error\u3011: \u63A5\u53E3\u83B7\u53D6\u5F02\u5E38")),console.log(o);return}try{yield this.checkApiOutputDir()}catch(o){console.log(u.red("\u3010error\u3011: \u68C0\u67E5\u8F93\u51FA\u76EE\u5F55\u5F02\u5E38")),console.log(o);return}t&&(yield this.creatBaseFile());try{yield this.createFile()}catch(o){console.log(u.red("\u3010error\u3011: createFile \u5F02\u5E38")),console.log(o)}})}checkApiOutputDir(){const{outputPath:n}=this.config;console.log(u.blueBright(`\u3010info\u3011\u8F93\u51FA\u76EE\u5F55 ${n}`));try{c.statSync(n,{bigint:!0})}catch(i){c.mkdirSync(n,{recursive:!0})}}creatBaseFile(){return L(this,null,function*(){const{outputPath:n}=this.config,i=p.join(__dirname,"../template/api"),l=c.readdirSync(i),e=c.readdirSync(n);for(const s of l)if(!e.includes(s))try{const d=c.readFileSync(p.join(i,s));c.writeFileSync(p.join(n,s),d)}catch(d){console.log(u.red("\u3010error\u3011: \u57FA\u7840\u6587\u4EF6\u751F\u6210\u5F02\u5E38")),console.log(d)}})}createFile(){return L(this,null,function*(){const{apiBaseName:n,outputPath:i,customMethodName:l}=this.config;this.apiList.forEach(e=>{var q,I,R;const s=F=>F.replace(/(-[a-z])|(^[a-z])/g,h=>h.replace("-","").toLocaleUpperCase()),d=new RegExp(`(${n})?(/)?(?<apiDirName>[a-zA-Z0-9_]+)/.*$`),{apiDirName:t}=((q=d.exec(e.path))==null?void 0:q.groups)||{},o=l||e.name,a=s(`${t}-`+o);try{c.statSync(p.join(i,t)).isDirectory()}catch(F){c.mkdirSync(p.join(i,t))}let $="";try{$=c.readFileSync(p.join(i,t,"models.ts")).toString()}catch(F){c.writeFileSync(p.join(i,`./${t}/models.ts`),"")}let g=[],w=[];try{g=(I=e.paramList)!=null&&I.length?[$?"":"/**************************************************/",`/** ${e.title} RequestModel */`,`export interface ${a}ReqModel {`,...x.getInterface({list:e.paramList||[],config:this.config}),"}",""]:[],w=(R=e.returnList)!=null&&R.length?[g.length?"":"/**************************************************/",`/** ${e.title} ResponseModel */`,`export interface ${a}ResModel {`,...x.getInterface({list:e.returnList||[],config:this.config}),"}",""]:[]}catch(F){throw console.log(u.red(`\u3010error\u3011\u7C7B\u578B\u751F\u6210\u5931\u8D25 projectId: ${this.config.projectId} methodId: ${e.id} path: ${e.path}`)),u.red(F)}$.includes(`export interface ${a}ReqModel {`)?console.log(u.yellowBright(`\u3010warning\u3011./${t}/models.ts \u5DF2\u5B58\u5728 ${a}ReqModel`)):g.length&&(c.appendFileSync(p.join(i,`./${t}/models.ts`),g.join(`
5
+ `)),console.log(u.greenBright(`\u3010success\u3011./${t}/models.ts \u6210\u529F\u6DFB\u52A0 ${a}ReqModel`))),$.includes(`export interface ${a}ResModel {`)?console.log(u.yellowBright(`\u3010warning\u3011./${t}/models.ts \u5DF2\u5B58\u5728 ${a}ResModel`)):w.length&&(c.appendFileSync(p.join(i,`./${t}/models.ts`),w.join(`
6
+ `)),console.log(u.greenBright(`\u3010success\u3011./${t}/models.ts \u6210\u529F\u6DFB\u52A0 ${a}ResModel`)));const b=[e.title&&` /** ${e.title} */`,` ${o}(${g.length?`params: M.${a}ReqModel`:""}) {`,` return axios.${e.method.toLowerCase()}<ApiResponse<${w.length?`M.${a}ResModel`:"any"}>>(`,` \`\${ApiPrefix}/${e.path}\`,`,g.length&&` ${["post","put","patch"].includes(e.method.toLowerCase())?"params":"{ params }"},`," );"," },"].filter(Boolean);/^[a-zA-Z]+$/.test((e.method||"").trim())||console.log(u.yellowBright(`\u3010warning\u3011\u63A5\u53E3\u8BF7\u6C42\u7C7B\u578B\u5F02\u5E38\uFF0C\u8BF7\u624B\u52A8\u8865\u5168 method\uFF1A${e.method} path: ${e.path} methodId: ${this.config.methodId} projectId: ${this.config.projectId}`));try{const F=c.readFileSync(p.join(i,t,"api.ts")).toString(),h=F.split(`
7
+ `);if(F.includes(` ${o}(`)){const j=h.findIndex(A=>A.includes(` ${o}(`)),N=h.findIndex((A,O)=>O>j&&A===" },");console.log(u.yellowBright([`\u3010warning\u3011./${t}/api.ts \u5DF2\u5B58\u5728api`,...h.slice(j,N+1).map(A=>` ${A}`)].join(`
8
+ `))),console.log(u.yellowBright(`\u3010warning\u3011\u5F53\u524D\u9700\u8981\u751F\u6210\u7684 path \u4E3A ${e.path}, methodName \u4E3A ${o}`))}else h.splice(h.map(j=>j.includes("}")).lastIndexOf(!0),0,b.join(`
9
+ `)),c.writeFileSync(p.join(i,`./${t}/api.ts`),h.join(`
10
+ `)),console.log(u.greenBright(`\u3010success\u3011./${t}/api.ts \u6210\u529F\u6DFB\u52A0 ${o}`))}catch(F){c.writeFileSync(p.join(i,`./${t}/api.ts`),["import axios from 'axios';","","import * as M from './models';","import { ApiResponse } from '../responseModel';","import { ApiPrefix } from '../apiPrefix';","","export * from './models';","",`export const ${s(t)}Api = {`,...b,"};",""].join(`
11
+ `)),console.log(u.greenBright(`\u3010success\u3011./${t}/api.ts \u6210\u529F\u6DFB\u52A0 ${o}`));const h=c.readFileSync(p.join(i,"index.ts")).toString();if(!h.includes(`export * from './${t}/api'`)){const j=h.split(`
12
+ `);j.push(`export * from './${t}/api';`);const N=j.slice(1).filter(Boolean);N.sort((A,O)=>A.localeCompare(O)),c.writeFileSync(p.join(i,"index.ts"),[j[0]||"","",...N,""].join(`
13
+ `))}}})})}},m=require("fs"),S=require("path"),{program:M}=require("commander"),E=require("chalk");M.name("sy-api-pro").version(require(S.resolve(__dirname,"../package.json")).version),M.command("init").description("\u521D\u59CB\u5316\u914D\u7F6E\u6587\u4EF6").option("-p, --path <char>","","./src/apis").action((r,n,i)=>{const l=S.join(process.cwd(),r.path),e=S.join(l,".api-config.ts");try{if(m.existsSync(l)||m.mkdirSync(l),m.existsSync(e))return console.log(E.yellowBright(`\u3010warning\u3011: ${e} \u914D\u7F6E\u6587\u4EF6\u5DF2\u5B58\u5728`));const s=m.readFileSync(S.join(__dirname,"../template/config/.api-config.ts"));m.writeFileSync(e,s),console.log(E.greenBright(`\u3010success\u3011: \u914D\u7F6E\u6587\u4EF6\u5DF2\u751F\u6210, \u8DEF\u5F84\uFF1A${e}`))}catch(s){console.log(E.red("\u3010error\u3011: \u914D\u7F6E\u6587\u4EF6\u751F\u6210\u5F02\u5E38")),console.log(s)}}),M.command("create").description("\u751F\u6210api\u6587\u4EF6\u53CA\u7C7B\u578B\u5B9A\u4E49").requiredOption("-i, --id <id>","methodId").option("-n, --name <name>","customMethodName").requiredOption("--config <filePath>","configFilePath").requiredOption("--project-id <id>","projectId").action((r,n,i)=>{const{id:l,name:e,config:s,projectId:d}=r;if(!l||!/^\d+$/.test(l))throw E.red("\u3010error\u3011\u8BF7\u4F20\u5165\u6B63\u786E\u7684 id");const t=require(S.resolve(process.cwd(),s)),o=(t.projects||[]).find(a=>+a.projectId==+d);if(o){if(!o.branchId)throw E.red("\u3010error\u3011\u8BF7\u4F20\u5165\u6B63\u786E\u7684 branchId");if(!t.api)throw E.red("\u3010error\u3011\u8BF7\u4F20\u5165\u6B63\u786E\u7684 api");new f({api:t.api,creatBaseFile:o.creatBaseFile||!0,methodId:l,customMethodName:e,outputPath:t.outputPath||"./src/apis",projectId:o.projectId,branchId:+o.branchId,outputDirName:o.outputDirName||"",apiBaseName:o.apiBaseName||"",ignoreParamsDTO:o.ignoreParamsDTO||[],deleteParentDTO:o.deleteParentDTO||[]})}else console.log(E.red(`\u3010error\u3011config \u914D\u7F6E\u6587\u4EF6\u4E2D projects \u672A\u5305\u542B\u4F20\u5165\u7684 projectId ${d}`))}),M.parse()});
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "sy-api-pro",
3
- "version": "0.0.10",
3
+ "version": "0.1.1",
4
4
  "main": "./bin/index.ts",
5
- "types": "./bin/model.d.ts",
5
+ "types": "./typings/config-option-models.ts",
6
6
  "bin": {
7
7
  "sy-api-pro": "./bin/index.ts"
8
8
  },
@@ -22,19 +22,20 @@
22
22
  "scripts": {
23
23
  "build": "vite build",
24
24
  "api": "ts-node src/index.ts --config ./src/.api-config.ts --project-id 804",
25
- "testDist": "ts-node bin/index.js --config ./src/.api-config.ts --project-id 804"
25
+ "test:dist-init": "ts-node bin/index.ts init",
26
+ "test:dist-create": "ts-node bin/index.ts create --config ./src/.api-config.ts --project-id 804"
26
27
  },
27
28
  "description": "...",
28
29
  "dependencies": {
29
- "axios": "^0.24.0",
30
- "chalk": "^4.1.2",
31
- "commander": "^8.3.0",
32
- "ts-node": "^10.4.0",
33
- "typescript": "^4.5.4",
34
- "@types/node": "^17.0.8"
30
+ "axios": "^0.26.1",
31
+ "chalk": "4.1.2",
32
+ "commander": "^9.1.0",
33
+ "ts-node": "^10.7.0",
34
+ "typescript": "^4.6.3",
35
+ "@types/node": "^17.0.23"
35
36
  },
36
37
  "devDependencies": {
37
38
  "rollup-plugin-terser": "^7.0.2",
38
- "vite": "^2.7.10"
39
+ "vite": "^2.9.1"
39
40
  }
40
41
  }
File without changes
File without changes
@@ -0,0 +1,19 @@
1
+ import { ConfigModels } from 'sy-api-pro';
2
+
3
+ const config: ConfigModels = {
4
+ outputPath: null, // 路径相对工程根目录【默认:'./src/apis'】
5
+ api: 'http://xxx.com', //
6
+ projects: [
7
+ {
8
+ projectId: null, // apidocs, url的 projectId 部分
9
+ branchId: null, // apidocs, url的 branchId 部分(与 scripts 中 --project-id 必须一致)
10
+ outputDirName: '', // 默认为获取到的appName
11
+ apiBaseName: '', //
12
+ creatBaseFile: true, // 生成基础文件 默认 true
13
+ ignoreParamsDTO: [], // string[];
14
+ deleteParentDTO: [], // (string | RegExp)[];
15
+ },
16
+ ],
17
+ };
18
+
19
+ module.exports = config;
package/bin/model.d.ts DELETED
@@ -1,13 +0,0 @@
1
- export interface ConfigModels {
2
- outputPath?: string;
3
- api: string;
4
- projects: {
5
- projectId: number | undefined;
6
- branchId: number | undefined;
7
- creatBaseFile?: boolean;
8
- outputDirName?: string;
9
- apiBaseName?: string;
10
- ignoreParamsDTO?: string[];
11
- deleteParentDTO?: (string | RegExp)[];
12
- }[]
13
- }