sy-api-pro 0.1.7 → 0.1.8

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.
Files changed (2) hide show
  1. package/dist/index.umd.js +13 -13
  2. package/package.json +8 -8
package/dist/index.umd.js CHANGED
@@ -1,13 +1,13 @@
1
- (function(D,w){typeof exports=="object"&&typeof module!="undefined"?w(require("axios")):typeof define=="function"&&define.amd?define(["axios"],w):(D=typeof globalThis!="undefined"?globalThis:D||self,w(D.axios))})(this,function(D){"use strict";var O=(D,w,y)=>new Promise((_,q)=>{var p=$=>{try{s(y.next($))}catch(F){q(F)}},d=$=>{try{s(y.throw($))}catch(F){q(F)}},s=$=>$.done?_($.value):Promise.resolve($.value).then(p,d);s((y=y.apply(D,w)).next())});function w(r){return r&&typeof r=="object"&&"default"in r?r:{default:r}}var y=w(D);const _=r=>{var o;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:u}=((o=new RegExp("^list<(?<listType>.+)>$").exec(n))==null?void 0:o.groups)||{};return u?`Array<${i[u]||"any"}>`:i[n]||"any"},q=Object.freeze({_getDesc(r){const n=(r.title||"").trim();return n?` // ${n}`:""},getInterface:function({list:r,config:{ignoreParamsDTO:n,deleteParentDTO:i}}){const u=r.map((t,c)=>t.level===0?c:null).filter(t=>t!==null);u.length>1&&u.push(r.length);const o=u.length>1?u.map((t,c)=>r.slice(t,u[c+1])):r,h=r.filter(t=>!t.json);return o.filter(t=>!n.includes(t.type)).filter(t=>t.json).map(t=>{const c=(t.json||"").split(`
2
- `);return c.forEach((e,l)=>{var I;const g=new RegExp('(?<space>\\s*)"(?<name>[a-zA-Z0-9]+)"\\s?:\\s*"(?<desc>.*)".*$');if(g.test(e)){const{space:j,name:b,desc:T}=((I=g.exec(e))==null?void 0:I.groups)||{},v=(b||"").trim(),S=(T||"").trim(),M=h.filter(A=>(A.name||"").trim()+(A.title||"").trim()===v+S);if(M.length>=1){const[{type:A}]=M,R=t.required?"?":"";c[l]=e.replace(g,`${j+b+R}: ${_(A)};${S?` // ${S}`:""}`)}}/\s*"[a-zA-Z0-9]+"\s*:\s*.+$/.test(e)&&(c[l]=c[l].replace(/(\s*)"([a-zA-Z0-9]+)"\s?(:\s*.+)$/,"$1$2$3")),c[l]=c[l].replace(/(.*)\[\s+{$/,"$1Array<{").replace(/(.*)}\s*].*$/,"$1}>")}),i.some(e=>{const l=Object.prototype.toString.call(e);if(l==="[object RegExp]")return e.test(t.type);if(l==="[object String]")return e===t.type})?c.slice(1,-1).join(`
3
- `):[` ${t.name}${t.required?"":"?"}: {${this._getDesc(t)}`,...c.slice(1,-1).map(e=>` ${e}`)," }"].join(`
4
- `)})}}),p=require("fs"),d=require("path"),s=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 $=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 O(this,null,function*(){const{api:n,branchId:i,projectId:u,outputDirName:o,outputPath:h,methodId:t,creatBaseFile:c}=this.config;try{const{data:a}=yield y.default.get(`${n}/api/project/getProjectWithBranchById?id=${u}`);this.config.outputPath=d.join(process.cwd(),h,o||a.body.name);const e=a.body.branchList.find(g=>g.id===i);if(e)console.log(s.blueBright(`\u3010info\u3011\u6B63\u5728\u4F7F\u7528 branchName: ${e.name} branchId: ${i} methodId: ${t}`));else throw s.red(`\u3010error\u3011branchId ${i} \u4E0D\u5B58\u5728`);const l=yield y.default.get(`${n}/api/method/getMethodById?id=${t}`);this.apiList=[l.data.body]}catch(a){console.log(s.red("\u3010error\u3011: \u63A5\u53E3\u83B7\u53D6\u5F02\u5E38")),console.log(a);return}try{yield this.checkApiOutputDir()}catch(a){console.log(s.red("\u3010error\u3011: \u68C0\u67E5\u8F93\u51FA\u76EE\u5F55\u5F02\u5E38")),console.log(a);return}c&&(yield this.creatBaseFile());try{yield this.createFile()}catch(a){console.log(s.red("\u3010error\u3011: createFile \u5F02\u5E38")),console.log(a)}})}checkApiOutputDir(){const{outputPath:n}=this.config;console.log(s.blueBright(`\u3010info\u3011\u8F93\u51FA\u76EE\u5F55 ${n}`));try{p.statSync(n,{bigint:!0})}catch(i){p.mkdirSync(n,{recursive:!0})}}creatBaseFile(){return O(this,null,function*(){const{outputPath:n}=this.config,i=d.join(__dirname,"../template/api"),u=p.readdirSync(i),o=p.readdirSync(n);for(const h of u)if(!o.includes(h))try{const t=p.readFileSync(d.join(i,h));p.writeFileSync(d.join(n,h),t)}catch(t){console.log(s.red("\u3010error\u3011: \u57FA\u7840\u6587\u4EF6\u751F\u6210\u5F02\u5E38")),console.log(t)}})}createFile(){return O(this,null,function*(){const{apiBaseName:n,outputPath:i,customMethodName:u}=this.config;this.apiList.forEach(o=>{var M,A,R;const h=f=>f.replace(/(-[a-z])|(^[a-z])/g,m=>m.replace("-","").toLocaleUpperCase()),t=o.path.startsWith("/")?o.path:`/${o.path}`,c=n.startsWith("/")?n:`/${n}`,a=new RegExp(`(${c})?(/)?(?<apiDirName>[a-zA-Z0-9_]+)/.*$`),{apiDirName:e}=((M=a.exec(t))==null?void 0:M.groups)||{},l=u||o.name,g=h(`${e}-`+l);try{p.statSync(d.join(i,e)).isDirectory()}catch(f){p.mkdirSync(d.join(i,e))}let I="";try{I=p.readFileSync(d.join(i,e,"models.ts")).toString()}catch(f){p.writeFileSync(d.join(i,`./${e}/models.ts`),"")}let j=[],b=[];try{const f=q.getInterface({list:o.paramList||[],config:this.config});j=((A=o.paramList)==null?void 0:A.length)&&f.length?[I?"":"/* ************************************************ */",`/** ${o.title} RequestModel */`,`export interface ${g}ReqModel {`,...f,"}",""]:[];const m=q.getInterface({list:o.returnList||[],config:this.config});b=((R=o.returnList)==null?void 0:R.length)&&m.length?[j.length?"":"/* ************************************************ */",`/** ${o.title} ResponseModel */`,`export interface ${g}ResModel {`,...m,"}",""]:[]}catch(f){throw console.log(s.red(`\u3010error\u3011\u7C7B\u578B\u751F\u6210\u5931\u8D25 projectId: ${this.config.projectId} methodId: ${o.id} path: ${t}`)),s.red(f)}I.includes(`export interface ${g}ReqModel {`)?console.log(s.yellowBright(`\u3010warning\u3011./${e}/models.ts \u5DF2\u5B58\u5728 ${g}ReqModel`)):j.length&&(p.appendFileSync(d.join(i,`./${e}/models.ts`),j.join(`
5
- `)),console.log(s.greenBright(`\u3010success\u3011./${e}/models.ts \u6210\u529F\u6DFB\u52A0 ${g}ReqModel`))),I.includes(`export interface ${g}ResModel {`)?console.log(s.yellowBright(`\u3010warning\u3011./${e}/models.ts \u5DF2\u5B58\u5728 ${g}ResModel`)):b.length&&(p.appendFileSync(d.join(i,`./${e}/models.ts`),b.join(`
6
- `)),console.log(s.greenBright(`\u3010success\u3011./${e}/models.ts \u6210\u529F\u6DFB\u52A0 ${g}ResModel`)));const S=[o.title&&` /** ${o.title} */`,` ${l}(${j.length?`params: M.${g}ReqModel`:""}) {`,` return axios.${o.method.toLowerCase()}<ApiResponse<${b.length?`M.${g}ResModel`:"any"}>>(`,` \`\${ApiPrefix}${t}\`,`,j.length&&` ${["post","put","patch"].includes(o.method.toLowerCase())?"params":"{ params }"},`," );"," },"].filter(Boolean);/^[a-zA-Z]+$/.test((o.method||"").trim())||console.log(s.yellowBright(`\u3010warning\u3011\u63A5\u53E3\u8BF7\u6C42\u7C7B\u578B\u5F02\u5E38\uFF0C\u8BF7\u624B\u52A8\u8865\u5168 method\uFF1A${o.method} path: ${t} methodId: ${this.config.methodId} projectId: ${this.config.projectId}`));try{const f=p.readFileSync(d.join(i,e,"api.ts")).toString(),m=f.split(`
7
- `);if(f.includes(` ${l}(`)){const B=m.findIndex(x=>x.includes(` ${l}(`)),N=m.findIndex((x,C)=>C>B&&x===" },");console.log(s.yellowBright([`\u3010warning\u3011./${e}/api.ts \u5DF2\u5B58\u5728api`,...m.slice(B,N+1).map(x=>` ${x}`)].join(`
8
- `))),console.log(s.yellowBright(`\u3010warning\u3011\u5F53\u524D\u9700\u8981\u751F\u6210\u7684 path \u4E3A ${t}, methodName \u4E3A ${l}`))}else m.splice(m.map(B=>B.includes("}")).lastIndexOf(!0),0,S.join(`
9
- `)),p.writeFileSync(d.join(i,`./${e}/api.ts`),m.join(`
10
- `)),console.log(s.greenBright(`\u3010success\u3011./${e}/api.ts \u6210\u529F\u6DFB\u52A0 ${l}`))}catch(f){p.writeFileSync(d.join(i,`./${e}/api.ts`),["import axios from 'axios';","","import * as M from './models';","import { ApiResponse } from '../responseModel';","import { ApiPrefix } from '../apiPrefix';","","export * from './models';","",`export const ${h(e)}Api = {`,...S,"};",""].join(`
11
- `)),console.log(s.greenBright(`\u3010success\u3011./${e}/api.ts \u6210\u529F\u6DFB\u52A0 ${l}`));const m=p.readFileSync(d.join(i,"index.ts")).toString();if(!m.includes(`export * from './${e}/api'`)){const B=m.split(`
12
- `);B.push(`export * from './${e}/api';`);const N=B.slice(1).filter(Boolean);N.sort((x,C)=>x.localeCompare(C)),p.writeFileSync(d.join(i,"index.ts"),[B[0]||"","",...N,""].join(`
13
- `))}}})})}},F=require("fs"),P=require("path"),{program:L}=require("commander"),E=require("chalk");L.name("sy-api-pro").version(require(P.resolve(__dirname,"../package.json")).version),L.command("init").description("\u521D\u59CB\u5316\u914D\u7F6E\u6587\u4EF6").option("-p, --path <char>","","./src/apis").action((r,n,i)=>{const u=P.join(process.cwd(),r.path),o=P.join(u,".api-config.ts");try{if(F.existsSync(u)||F.mkdirSync(u),F.existsSync(o))return console.log(E.yellowBright(`\u3010warning\u3011: ${o} \u914D\u7F6E\u6587\u4EF6\u5DF2\u5B58\u5728`));const h=F.readFileSync(P.join(__dirname,"../template/config/.api-config.ts"));F.writeFileSync(o,h),console.log(E.greenBright(`\u3010success\u3011: \u914D\u7F6E\u6587\u4EF6\u5DF2\u751F\u6210, \u8DEF\u5F84\uFF1A${o}`))}catch(h){console.log(E.red("\u3010error\u3011: \u914D\u7F6E\u6587\u4EF6\u751F\u6210\u5F02\u5E38")),console.log(h)}}),L.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)=>{var e;const{id:u,name:o,config:h,projectId:t}=r;if(!u||!/^\d+$/.test(u))throw E.red("\u3010error\u3011\u8BF7\u4F20\u5165\u6B63\u786E\u7684 id");const c=require(P.resolve(process.cwd(),h)),a=(c.projects||[]).find(l=>+l.projectId==+t);if(a){if(!a.branchId)throw E.red("\u3010error\u3011\u8BF7\u4F20\u5165\u6B63\u786E\u7684 branchId");if(!c.api)throw E.red("\u3010error\u3011\u8BF7\u4F20\u5165\u6B63\u786E\u7684 api");new $({api:c.api,creatBaseFile:(e=a.creatBaseFile)!=null?e:!0,methodId:u,customMethodName:o,outputPath:c.outputPath||"./src/apis",projectId:a.projectId,branchId:+a.branchId,outputDirName:a.outputDirName||"",apiBaseName:a.apiBaseName||"",ignoreParamsDTO:a.ignoreParamsDTO||[],deleteParentDTO:a.deleteParentDTO||[]})}else console.log(E.red(`\u3010error\u3011config \u914D\u7F6E\u6587\u4EF6\u4E2D projects \u672A\u5305\u542B\u4F20\u5165\u7684 projectId ${t}`))}),L.parse()});
1
+ (function(y,x){typeof exports=="object"&&typeof module!="undefined"?x(require("axios")):typeof define=="function"&&define.amd?define(["axios"],x):(y=typeof globalThis!="undefined"?globalThis:y||self,x(y.axios))})(this,function(y){"use strict";var N=(y,x,B)=>new Promise((d,h)=>{var a=f=>{try{j(B.next(f))}catch(w){h(w)}},O=f=>{try{j(B.throw(f))}catch(w){h(w)}},j=f=>f.done?d(f.value):Promise.resolve(f.value).then(a,O);j((B=B.apply(y,x)).next())});const x=l=>{var o;const n=(l||"").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:r}=((o=new RegExp("^list<(?<listType>.+)>$").exec(n))==null?void 0:o.groups)||{};return r?`Array<${i[r]||"any"}>`:i[n]||"any"},B=Object.freeze({_getDesc(l){const n=(l.title||"").trim();return n?` // ${n}`:""},getInterface:function({list:l,config:{ignoreParamsDTO:n,deleteParentDTO:i}}){const r=l.map((t,s)=>t.level===0?s:null).filter(t=>t!==null);r.length>1&&r.push(l.length);const o=r.length>1?r.map((t,s)=>l.slice(t,r[s+1])):l,g=l.filter(t=>!t.json);return o.filter(t=>!n.includes(t.type)).filter(t=>t.json).map(t=>{const s=(t.json||"").split(`
2
+ `);return s.forEach((e,p)=>{var S;const u=new RegExp('(?<space>\\s*)"(?<name>[a-zA-Z0-9]+)"\\s?:\\s*"(?<desc>.*)".*$');if(u.test(e)){const{space:I,name:q,desc:_}=((S=u.exec(e))==null?void 0:S.groups)||{},v=(q||"").trim(),M=(_||"").trim(),R=g.filter(D=>(D.name||"").trim()+(D.title||"").trim()===v+M);if(R.length>=1){const[{type:D}]=R,L=t.required?"?":"";s[p]=e.replace(u,`${I+q+L}: ${x(D)};${M?` // ${M}`:""}`)}}/\s*"[a-zA-Z0-9]+"\s*:\s*.+$/.test(e)&&(s[p]=s[p].replace(/(\s*)"([a-zA-Z0-9]+)"\s?(:\s*.+)$/,"$1$2$3")),s[p]=s[p].replace(/(.*)\[\s+{$/,"$1Array<{").replace(/(.*)}\s*].*$/,"$1}>")}),i.some(e=>{const p=Object.prototype.toString.call(e);if(p==="[object RegExp]")return e.test(t.type);if(p==="[object String]")return e===t.type})?s.slice(1,-1).join(`
3
+ `):[` ${t.name}${t.required?"":"?"}: {${this._getDesc(t)}`,...s.slice(1,-1).map(e=>` ${e}`)," }"].join(`
4
+ `)})}}),d=require("fs"),h=require("path"),a=require("chalk");y.interceptors.response.use(l=>{var n,i;return(i=(n=l.data)==null?void 0:n.head)!=null&&i.successful?l:Promise.reject(l)},l=>{throw l});const O=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 N(this,null,function*(){const{api:n,branchId:i,projectId:r,outputDirName:o,outputPath:g,methodId:t,creatBaseFile:s}=this.config;try{const{data:c}=yield y.get(`${n}/api/project/getProjectWithBranchById?id=${r}`);this.config.outputPath=h.join(process.cwd(),g,o||c.body.name);const e=c.body.branchList.find(u=>u.id===i);if(e)console.log(a.blueBright(`【info】正在使用 branchName: ${e.name} branchId: ${i} methodId: ${t}`));else throw a.red(`【error】branchId ${i} 不存在`);const p=yield y.get(`${n}/api/method/getMethodById?id=${t}`);this.apiList=[p.data.body]}catch(c){console.log(a.red("【error】: 接口获取异常")),console.log(c);return}try{yield this.checkApiOutputDir()}catch(c){console.log(a.red("【error】: 检查输出目录异常")),console.log(c);return}s&&(yield this.creatBaseFile());try{yield this.createFile()}catch(c){console.log(a.red("【error】: createFile 异常")),console.log(c)}})}checkApiOutputDir(){const{outputPath:n}=this.config;console.log(a.blueBright(`【info】输出目录 ${n}`));try{d.statSync(n,{bigint:!0})}catch(i){d.mkdirSync(n,{recursive:!0})}}creatBaseFile(){return N(this,null,function*(){const{outputPath:n}=this.config,i=h.join(__dirname,"../template/api"),r=d.readdirSync(i),o=d.readdirSync(n);for(const g of r)if(!o.includes(g))try{const t=d.readFileSync(h.join(i,g));d.writeFileSync(h.join(n,g),t)}catch(t){console.log(a.red("【error】: 基础文件生成异常")),console.log(t)}})}createFile(){return N(this,null,function*(){const{apiBaseName:n,outputPath:i,customMethodName:r}=this.config;this.apiList.forEach(o=>{var R,D,L;const g=$=>$.replace(/(-[a-z])|(^[a-z])/g,m=>m.replace("-","").toLocaleUpperCase()),t=o.path.startsWith("/")?o.path:`/${o.path}`,s=n.startsWith("/")?n:`/${n}`,c=new RegExp(`(${s})?(/)?(?<apiDirName>[a-zA-Z0-9_]+)/.*$`),{apiDirName:e}=((R=c.exec(t))==null?void 0:R.groups)||{},p=r||o.name,u=g(`${e}-`+p);try{d.statSync(h.join(i,e)).isDirectory()}catch($){d.mkdirSync(h.join(i,e))}let S="";try{S=d.readFileSync(h.join(i,e,"models.ts")).toString()}catch($){d.writeFileSync(h.join(i,`./${e}/models.ts`),"")}let I=[],q=[];try{const $=B.getInterface({list:o.paramList||[],config:this.config});I=(D=o.paramList)!=null&&D.length&&$.length?[S?"":"/* ************************************************ */",`/** ${o.title} RequestModel */`,`export interface ${u}ReqModel {`,...$,"}",""]:[];const m=B.getInterface({list:o.returnList||[],config:this.config});q=(L=o.returnList)!=null&&L.length&&m.length?[I.length?"":"/* ************************************************ */",`/** ${o.title} ResponseModel */`,`export interface ${u}ResModel {`,...m,"}",""]:[]}catch($){throw console.log(a.red(`【error】类型生成失败 projectId: ${this.config.projectId} methodId: ${o.id} path: ${t}`)),a.red($)}S.includes(`export interface ${u}ReqModel {`)?console.log(a.yellowBright(`【warning】./${e}/models.ts 已存在 ${u}ReqModel`)):I.length&&(d.appendFileSync(h.join(i,`./${e}/models.ts`),I.join(`
5
+ `)),console.log(a.greenBright(`【success】./${e}/models.ts 成功添加 ${u}ReqModel`))),S.includes(`export interface ${u}ResModel {`)?console.log(a.yellowBright(`【warning】./${e}/models.ts 已存在 ${u}ResModel`)):q.length&&(d.appendFileSync(h.join(i,`./${e}/models.ts`),q.join(`
6
+ `)),console.log(a.greenBright(`【success】./${e}/models.ts 成功添加 ${u}ResModel`)));const M=[o.title&&` /** ${o.title} */`,` ${p}(${I.length?`params: M.${u}ReqModel`:""}) {`,` return axios.${o.method.toLowerCase()}<ApiResponse<${q.length?`M.${u}ResModel`:"any"}>>(`,` \`\${ApiPrefix}${t}\`,`,I.length&&` ${["post","put","patch"].includes(o.method.toLowerCase())?"params":"{ params }"},`," );"," },"].filter(Boolean);/^[a-zA-Z]+$/.test((o.method||"").trim())||console.log(a.yellowBright(`【warning】接口请求类型异常,请手动补全 method:${o.method} path: ${t} methodId: ${this.config.methodId} projectId: ${this.config.projectId}`));try{const $=d.readFileSync(h.join(i,e,"api.ts")).toString(),m=$.split(`
7
+ `);if($.includes(` ${p}(`)){const b=m.findIndex(P=>P.includes(` ${p}(`)),A=m.findIndex((P,T)=>T>b&&P===" },");console.log(a.yellowBright([`【warning】./${e}/api.ts 已存在api`,...m.slice(b,A+1).map(P=>` ${P}`)].join(`
8
+ `))),console.log(a.yellowBright(`【warning】当前需要生成的 path ${t}, methodName ${p}`))}else m.splice(m.map(b=>b.includes("}")).lastIndexOf(!0),0,M.join(`
9
+ `)),d.writeFileSync(h.join(i,`./${e}/api.ts`),m.join(`
10
+ `)),console.log(a.greenBright(`【success】./${e}/api.ts 成功添加 ${p}`))}catch($){d.writeFileSync(h.join(i,`./${e}/api.ts`),["import axios from 'axios';","","import * as M from './models';","import { ApiResponse } from '../responseModel';","import { ApiPrefix } from '../apiPrefix';","","export * from './models';","",`export const ${g(e)}Api = {`,...M,"};",""].join(`
11
+ `)),console.log(a.greenBright(`【success】./${e}/api.ts 成功添加 ${p}`));const m=d.readFileSync(h.join(i,"index.ts")).toString();if(!m.includes(`export * from './${e}/api'`)){const b=m.split(`
12
+ `);b.push(`export * from './${e}/api';`);const A=b.slice(1).filter(Boolean);A.sort((P,T)=>P.localeCompare(T)),d.writeFileSync(h.join(i,"index.ts"),[b[0]||"","",...A,""].join(`
13
+ `))}}})})}},j=require("fs"),f=require("path"),{program:w}=require("commander"),F=require("chalk");w.name("sy-api-pro").version(require(f.resolve(__dirname,"../package.json")).version),w.command("init").description("初始化配置文件").option("-p, --path <char>","","./src/apis").action((l,n,i)=>{const r=f.join(process.cwd(),l.path),o=f.join(r,".api-config.ts");try{if(j.existsSync(r)||j.mkdirSync(r),j.existsSync(o))return console.log(F.yellowBright(`【warning】: ${o} 配置文件已存在`));const g=j.readFileSync(f.join(__dirname,"../template/config/.api-config.ts"));j.writeFileSync(o,g),console.log(F.greenBright(`【success】: 配置文件已生成, 路径:${o}`))}catch(g){console.log(F.red("【error】: 配置文件生成异常")),console.log(g)}}),w.command("create").description("生成api文件及类型定义").requiredOption("-i, --id <id>","methodId").option("-n, --name <name>","customMethodName").requiredOption("--config <filePath>","configFilePath").requiredOption("--project-id <id>","projectId").action((l,n,i)=>{var e;const{id:r,name:o,config:g,projectId:t}=l;if(!r||!/^\d+$/.test(r))throw F.red("【error】请传入正确的 id");const s=require(f.resolve(process.cwd(),g)),c=(s.projects||[]).find(p=>+p.projectId==+t);if(c){if(!c.branchId)throw F.red("【error】请传入正确的 branchId");if(!s.api)throw F.red("【error】请传入正确的 api");new O({api:s.api,creatBaseFile:(e=c.creatBaseFile)!=null?e:!0,methodId:r,customMethodName:o,outputPath:s.outputPath||"./src/apis",projectId:c.projectId,branchId:+c.branchId,outputDirName:c.outputDirName||"",apiBaseName:c.apiBaseName||"",ignoreParamsDTO:c.ignoreParamsDTO||[],deleteParentDTO:c.deleteParentDTO||[]})}else console.log(F.red(`【error】config 配置文件中 projects 未包含传入的 projectId ${t}`))}),w.parse()});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sy-api-pro",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "main": "./bin/index.ts",
5
5
  "types": "./bin/model.d.ts",
6
6
  "bin": {
@@ -29,15 +29,15 @@
29
29
  },
30
30
  "description": "...",
31
31
  "dependencies": {
32
- "axios": "^0.26.1",
33
- "chalk": "4.1.2",
34
- "commander": "^9.1.0",
35
- "ts-node": "9.1.1",
36
- "typescript": "4.9.4",
37
- "@types/node": "^17.0.23"
32
+ "@types/node": "^18.15.5",
33
+ "axios": "^1.3.4",
34
+ "chalk": "^4.1.2",
35
+ "commander": "^10.0.0",
36
+ "ts-node": "^10.9.1",
37
+ "typescript": "^5.0.2"
38
38
  },
39
39
  "devDependencies": {
40
40
  "rollup-plugin-terser": "^7.0.2",
41
- "vite": "^2.9.1"
41
+ "vite": "^4.2.1"
42
42
  }
43
43
  }