sy-api-pro 0.0.9 → 0.1.0

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,12 +1,13 @@
1
- var M=(b,j,f)=>new Promise((S,x)=>{var c=h=>{try{n(f.next(h))}catch(I){x(I)}},l=h=>{try{n(f.throw(h))}catch(I){x(I)}},n=h=>h.done?S(h.value):Promise.resolve(h.value).then(c,l);n((f=f.apply(b,j)).next())});(function(b,j){typeof exports=="object"&&typeof module!="undefined"?j(require("axios")):typeof define=="function"&&define.amd?define(["axios"],j):j((b=typeof globalThis!="undefined"?globalThis:b||self).axios)})(this,function(b){"use strict";function j(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var f=j(b);const S=e=>{var o;const r=(e||"").toLowerCase(),d={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:s}=((o=/^list<(?<listType>.+)>$/.exec(r))==null?void 0:o.groups)||{};return s?`Array<${d[s]||"any"}>`:d[r]||"any"},x=Object.freeze({_getDesc(e){const r=(e.title||"").trim();return r?` // ${r}`:""},getInterface:function({list:e,config:{ignoreParamsDTO:r,deleteParentDTO:d}}){const s=e.filter(o=>!o.id);return e.filter(o=>o.id&&!r.includes(o.type)).map(o=>{if(o.id&&o.json){const t=o.json.split(`
2
- `);return t.forEach((a,i)=>{var $;const u=/(?<space>\s*)"(?<name>[a-zA-Z0-9]+)"\s?:\s*"(?<desc>.*)".*$/;if(u.test(a)){const{space:w,name:P,desc:p}=(($=u.exec(a))==null?void 0:$.groups)||{},y=(P||"").trim(),g=(p||"").trim(),q=s.filter(B=>(B.name||"").trim()+(B.title||"").trim()===y+g);if(q.length>=1){const[{type:B}]=q,A=o.required?"?":"";t[i]=a.replace(u,`${w+P+A}: ${S(B)};${g?` // ${g}`:""}`)}}/\s*"[a-zA-Z0-9]+"\s*:\s*.+$/.test(a)&&(t[i]=t[i].replace(/(\s*)"([a-zA-Z0-9]+)"\s?(:\s*.+)$/,"$1$2$3")),t[i]=t[i].replace(/(.*)\[\s+{$/,"$1Array<{").replace(/(.*)}\s*].*$/,"$1}>")}),d.some(a=>{const i=Object.prototype.toString.call(a);return i==="[object RegExp]"?a.test(o.type):i==="[object String]"?a===o.type:void 0})?t.slice(1,-1).join(`
3
- `):[` ${o.name}${o.required?"":"?"}: {${this._getDesc(o)}`,...t.slice(1,-1).map(a=>` ${a}`)," }"].join(`
4
- `)}return` ${o.name}${o.required?"":"?"}: ${S(o.type)};${this._getDesc(o)}`})}}),c=require("fs"),l=require("path"),n=require("chalk");f.default.interceptors.response.use(e=>{var r,d;return((d=(r=e.data)==null?void 0:r.head)==null?void 0:d.successful)?e:Promise.reject(e)},e=>{throw e});const h=require("path"),{program:I}=require("commander"),D=require("chalk");I.version(require(h.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:O,name:N,config:R,projectId:v}=I.opts();if(!O||!/^\d+$/.test(O))throw D.red("\u3010error\u3011\u8BF7\u4F20\u5165\u6B63\u786E\u7684 id");const F=require(h.resolve(process.cwd(),R)),m=(F.projects||[]).find(e=>+e.projectId==+v);if(m){if(!m.branchId)throw D.red("\u3010error\u3011\u8BF7\u4F20\u5165\u6B63\u786E\u7684 branchId");if(!F.api)throw D.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 M(this,null,function*(){const{api:e,branchId:r,projectId:d,outputDirName:s,outputPath:o,methodId:t,creatBaseFile:a}=this.config;try{const{data:i}=yield f.default.get(`${e}/api/project/getProjectWithBranchById?id=${d}`);this.config.outputPath=l.join(process.cwd(),o,s||i.body.name);const u=i.body.branchList.find(w=>w.id===r);if(!u)throw n.red(`\u3010error\u3011branchId ${r} \u4E0D\u5B58\u5728`);console.log(n.blueBright(`\u3010info\u3011\u6B63\u5728\u4F7F\u7528 branchName: ${u.name} branchId: ${r} methodId: ${t}`));const $=yield f.default.get(`${e}/api/method/getMethodById?id=${t}`);this.apiList=[$.data.body]}catch(i){return console.log(n.red("\u3010error\u3011: \u63A5\u53E3\u83B7\u53D6\u5F02\u5E38")),void console.log(i)}try{yield this.checkApiOutputDir()}catch(i){return console.log(n.red("\u3010error\u3011: \u68C0\u67E5\u8F93\u51FA\u76EE\u5F55\u5F02\u5E38")),void console.log(i)}a&&(yield this.creatBaseFile());try{yield this.createFile()}catch(i){console.log(n.red("\u3010error\u3011: createFile \u5F02\u5E38")),console.log(i)}})}checkApiOutputDir(){const{outputPath:e}=this.config;console.log(n.blueBright(`\u3010info\u3011\u8F93\u51FA\u76EE\u5F55 ${e}`));try{c.statSync(e,{bigint:!0})}catch(r){c.mkdirSync(e,{recursive:!0})}}creatBaseFile(){return M(this,null,function*(){const{outputPath:e}=this.config,r=l.join(__dirname,"../template"),d=c.readdirSync(r),s=c.readdirSync(e);for(const o of d)if(!s.includes(o))try{const t=c.readFileSync(l.join(r,o));c.writeFileSync(l.join(e,o),t)}catch(t){console.log(n.red("\u3010error\u3011: \u57FA\u7840\u6587\u4EF6\u751F\u6210\u5F02\u5E38")),console.log(t)}})}createFile(){return M(this,null,function*(){const{apiBaseName:e,outputPath:r,customMethodName:d}=this.config;this.apiList.forEach(s=>{var P;const o=p=>p.replace(/(-[a-z])|(^[a-z])/g,y=>y.replace("-","").toLocaleUpperCase()),t=s.path.replace(e,"").split("/")[1],a=d||s.name,i=o(`${t}-`+a);try{c.statSync(l.join(r,t)).isDirectory()}catch(p){c.mkdirSync(l.join(r,t))}const u=(P=s.paramList)==null?void 0:P.length;let $=[];try{$=["/**************************************************/",...u?[`/** ${s.title} RequestModel */`,`export interface ${i}ReqModel {`,...x.getInterface({list:s.paramList||[],config:this.config}),"}",""]:[],`/** ${s.title} ResponseModel */`,`export interface ${i}ResModel {`,...x.getInterface({list:s.returnList||[],config:this.config}),"}",""]}catch(p){throw console.log(n.red(`\u3010error\u3011\u7C7B\u578B\u751F\u6210\u5931\u8D25 projectId: ${this.config.projectId} methodId: ${s.id} path: ${s.path}`)),n.red(p)}try{c.readFileSync(l.join(r,t,"models.ts")).toString().includes(`export interface ${i}ReqModel {`)?console.log(n.yellowBright(`\u3010warning\u3011./${t}/models.ts \u5DF2\u5B58\u5728 ${i}ReqModel`)):(c.appendFileSync(l.join(r,`./${t}/models.ts`),[""].concat($).join(`
5
- `)),console.log(n.greenBright(`\u3010success\u3011./${t}/models.ts \u6210\u529F\u6DFB\u52A0 ${i}ReqModel`)))}catch(p){c.writeFileSync(l.join(r,`./${t}/models.ts`),$.join(`
6
- `)),console.log(n.greenBright(`\u3010success\u3011./${t}/models.ts \u6210\u529F\u6DFB\u52A0 ${i}ReqModel`))}const w=[` /** ${s.title} */`,` ${a}(${u?`params: M.${i}ReqModel`:""}) {`,` return axios.${s.method.toLowerCase()}<ApiResponse<M.${i}ResModel>>(`,` \`\${ApiPrefix}/${s.path}\`,`,u&&` ${["post","put","patch"].includes(s.method.toLowerCase())?"params":"{ params }"},`," );"," },"].filter(Boolean);/^[a-zA-Z]+$/.test((s.method||"").trim())||console.log(n.yellowBright(`\u3010warning\u3011\u63A5\u53E3\u8BF7\u6C42\u7C7B\u578B\u5F02\u5E38\uFF0C\u8BF7\u624B\u52A8\u8865\u5168 method\uFF1A${s.method} path: ${s.path} methodId: ${this.config.methodId} projectId: ${this.config.projectId}`));try{const p=c.readFileSync(l.join(r,t,"api.ts")).toString();if(p.includes(` ${a}(`))console.log(n.yellowBright(`\u3010warning\u3011./${t}/api.ts \u5DF2\u5B58\u5728 ${a}`));else{const y=p.split(`
7
- `);y.splice(y.map(g=>g.includes("}")).lastIndexOf(!0),0,w.join(`
8
- `)),c.writeFileSync(l.join(r,`./${t}/api.ts`),y.join(`
9
- `)),console.log(n.greenBright(`\u3010success\u3011./${t}/api.ts \u6210\u529F\u6DFB\u52A0 ${a}`))}}catch(y){c.writeFileSync(l.join(r,`./${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 ${o(t)}Api = {`,...w,"};"].join(`
10
- `)),console.log(n.greenBright(`\u3010success\u3011./${t}/api.ts \u6210\u529F\u6DFB\u52A0 ${a}`));const p=c.readFileSync(l.join(r,"index.ts")).toString();if(!p.includes(`export * from './${t}/api'`)){const g=p.split(`
11
- `);g.push(`export * from './${t}/api';`);const q=g.slice(1).filter(Boolean);q.sort((B,A)=>B.localeCompare(A)),c.writeFileSync(l.join(r,"index.ts"),[g[0]||"","",...q,""].join(`
12
- `))}}})})}}({api:F.api,creatBaseFile:m.creatBaseFile||!0,methodId:O,customMethodName:N,outputPath:F.outputPath||"./src/apis",projectId:m.projectId,branchId:+m.branchId,outputDirName:m.outputDirName||"",apiBaseName:m.apiBaseName||"",ignoreParamsDTO:m.ignoreParamsDTO||[],deleteParentDTO:m.deleteParentDTO||[]})}else console.log(D.red(`\u3010error\u3011config \u914D\u7F6E\u6587\u4EF6\u4E2D projects \u672A\u5305\u542B\u4F20\u5165\u7684 projectId ${v}`))});
1
+ var _=(O,P,x)=>new Promise((D,N)=>{var R=t=>{try{c(x.next(t))}catch(w){N(w)}},a=t=>{try{c(x.throw(t))}catch(w){N(w)}},c=t=>t.done?D(t.value):Promise.resolve(t.value).then(R,a);c((x=x.apply(O,P)).next())});(function(O,P){typeof exports=="object"&&typeof module!="undefined"?P(require("axios")):typeof define=="function"&&define.amd?define(["axios"],P):P((O=typeof globalThis!="undefined"?globalThis:O||self).axios)})(this,function(O){"use strict";function P(r){return r&&typeof r=="object"&&"default"in r?r:{default:r}}var x=P(O),D={};const N=r=>{var e;const u=(r||"").toLowerCase(),b={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:f}=((e=/^list<(?<listType>.+)>$/.exec(u))==null?void 0:e.groups)||{};return f?`Array<${b[f]||"any"}>`:b[u]||"any"},R=Object.freeze({_getDesc(r){const u=(r.title||"").trim();return u?` // ${u}`:""},getInterface:function({list:r,config:{ignoreParamsDTO:u,deleteParentDTO:b}}){const f=r.filter(e=>!e.id);return r.filter(e=>e.id&&!u.includes(e.type)).map(e=>{if(e.id&&e.json){const p=e.json.split(`
2
+ `);return p.forEach((h,g)=>{var l;const m=/(?<space>\s*)"(?<name>[a-zA-Z0-9]+)"\s?:\s*"(?<desc>.*)".*$/;if(m.test(h)){const{space:n,name:B,desc:o}=((l=m.exec(h))==null?void 0:l.groups)||{},j=(B||"").trim(),$=(o||"").trim(),i=f.filter(s=>(s.name||"").trim()+(s.title||"").trim()===j+$);if(i.length>=1){const[{type:s}]=i,d=e.required?"?":"";p[g]=h.replace(m,`${n+B+d}: ${N(s)};${$?` // ${$}`:""}`)}}/\s*"[a-zA-Z0-9]+"\s*:\s*.+$/.test(h)&&(p[g]=p[g].replace(/(\s*)"([a-zA-Z0-9]+)"\s?(:\s*.+)$/,"$1$2$3")),p[g]=p[g].replace(/(.*)\[\s+{$/,"$1Array<{").replace(/(.*)}\s*].*$/,"$1}>")}),b.some(h=>{const g=Object.prototype.toString.call(h);return g==="[object RegExp]"?h.test(e.type):g==="[object String]"?h===e.type:void 0})?p.slice(1,-1).join(`
3
+ `):[` ${e.name}${e.required?"":"?"}: {${this._getDesc(e)}`,...p.slice(1,-1).map(h=>` ${h}`)," }"].join(`
4
+ `)}return` ${e.name}${e.required?"":"?"}: ${N(e.type)};${this._getDesc(e)}`})}}),a=require("fs"),c=require("path"),t=require("chalk");x.default.interceptors.response.use(r=>{var u,b;return(b=(u=r.data)==null?void 0:u.head)!=null&&b.successful?r:Promise.reject(r)},r=>{throw r});const w=require("path"),{program:v}=require("commander"),q=require("chalk");v.name("sy-api-pro").version(require(w.resolve(__dirname,"../package.json")).version),v.command("init").description("\u521D\u59CB\u5316\u914D\u7F6E\u6587\u4EF6").option("-p, --path <char>","","../src/apis").action((r,u,b)=>{const f=w.join(process.cwd(),r.path),e=w.join(f,".api-config.ts");try{if(D.existsSync(f)||D.mkdirSync(f),D.existsSync(e))return console.log(q.yellowBright(`\u3010warning\u3011: ${e} \u914D\u7F6E\u6587\u4EF6\u5DF2\u5B58\u5728`));const p=D.readFileSync(w.join(__dirname,"../template/config/.api-config.ts"));D.writeFileSync(e,p),console.log(q.greenBright(`\u3010success\u3011: \u914D\u7F6E\u6587\u4EF6\u5DF2\u751F\u6210, \u8DEF\u5F84\uFF1A${e}`))}catch(p){console.log(q.red("\u3010error\u3011: \u914D\u7F6E\u6587\u4EF6\u751F\u6210\u5F02\u5E38")),console.log(p)}}),v.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,u,b)=>{const{id:f,name:e,config:p,projectId:h}=r;if(!f||!/^\d+$/.test(f))throw q.red("\u3010error\u3011\u8BF7\u4F20\u5165\u6B63\u786E\u7684 id");const g=require(w.resolve(process.cwd(),p)),m=(g.projects||[]).find(l=>+l.projectId==+h);if(m){if(!m.branchId)throw q.red("\u3010error\u3011\u8BF7\u4F20\u5165\u6B63\u786E\u7684 branchId");if(!g.api)throw q.red("\u3010error\u3011\u8BF7\u4F20\u5165\u6B63\u786E\u7684 api");new class{constructor(l){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,l),this.getApiData()}getApiData(){return _(this,null,function*(){const{api:l,branchId:n,projectId:B,outputDirName:o,outputPath:j,methodId:$,creatBaseFile:i}=this.config;try{const{data:s}=yield x.default.get(`${l}/api/project/getProjectWithBranchById?id=${B}`);this.config.outputPath=c.join(process.cwd(),j,o||s.body.name);const d=s.body.branchList.find(S=>S.id===n);if(!d)throw t.red(`\u3010error\u3011branchId ${n} \u4E0D\u5B58\u5728`);console.log(t.blueBright(`\u3010info\u3011\u6B63\u5728\u4F7F\u7528 branchName: ${d.name} branchId: ${n} methodId: ${$}`));const A=yield x.default.get(`${l}/api/method/getMethodById?id=${$}`);this.apiList=[A.data.body]}catch(s){return console.log(t.red("\u3010error\u3011: \u63A5\u53E3\u83B7\u53D6\u5F02\u5E38")),void console.log(s)}try{yield this.checkApiOutputDir()}catch(s){return console.log(t.red("\u3010error\u3011: \u68C0\u67E5\u8F93\u51FA\u76EE\u5F55\u5F02\u5E38")),void console.log(s)}i&&(yield this.creatBaseFile());try{yield this.createFile()}catch(s){console.log(t.red("\u3010error\u3011: createFile \u5F02\u5E38")),console.log(s)}})}checkApiOutputDir(){const{outputPath:l}=this.config;console.log(t.blueBright(`\u3010info\u3011\u8F93\u51FA\u76EE\u5F55 ${l}`));try{a.statSync(l,{bigint:!0})}catch(n){a.mkdirSync(l,{recursive:!0})}}creatBaseFile(){return _(this,null,function*(){const{outputPath:l}=this.config,n=c.join(__dirname,"../template/api"),B=a.readdirSync(n),o=a.readdirSync(l);for(const j of B)if(!o.includes(j))try{const $=a.readFileSync(c.join(n,j));a.writeFileSync(c.join(l,j),$)}catch($){console.log(t.red("\u3010error\u3011: \u57FA\u7840\u6587\u4EF6\u751F\u6210\u5F02\u5E38")),console.log($)}})}createFile(){return _(this,null,function*(){const{apiBaseName:l,outputPath:n,customMethodName:B}=this.config;this.apiList.forEach(o=>{var C,Z,E;const j=I=>I.replace(/(-[a-z])|(^[a-z])/g,y=>y.replace("-","").toLocaleUpperCase()),$=new RegExp(`(${l})?(/)?(?<apiDirName>[a-zA-Z0-9_]+)/.*$`),{apiDirName:i}=((C=$.exec(o.path))==null?void 0:C.groups)||{},s=B||o.name,d=j(`${i}-`+s);try{a.statSync(c.join(n,i)).isDirectory()}catch(I){a.mkdirSync(c.join(n,i))}let A="";try{A=a.readFileSync(c.join(n,i,"models.ts")).toString()}catch(I){a.writeFileSync(c.join(n,`./${i}/models.ts`),"")}let S=[],L=[];try{S=(Z=o.paramList)!=null&&Z.length?[A?"":"/**************************************************/",`/** ${o.title} RequestModel */`,`export interface ${d}ReqModel {`,...R.getInterface({list:o.paramList||[],config:this.config}),"}",""]:[],L=(E=o.returnList)!=null&&E.length?[S.length?"":"/**************************************************/",`/** ${o.title} ResponseModel */`,`export interface ${d}ResModel {`,...R.getInterface({list:o.returnList||[],config:this.config}),"}",""]:[]}catch(I){throw console.log(t.red(`\u3010error\u3011\u7C7B\u578B\u751F\u6210\u5931\u8D25 projectId: ${this.config.projectId} methodId: ${o.id} path: ${o.path}`)),t.red(I)}A.includes(`export interface ${d}ReqModel {`)?console.log(t.yellowBright(`\u3010warning\u3011./${i}/models.ts \u5DF2\u5B58\u5728 ${d}ReqModel`)):S.length&&(a.appendFileSync(c.join(n,`./${i}/models.ts`),S.join(`
5
+ `)),console.log(t.greenBright(`\u3010success\u3011./${i}/models.ts \u6210\u529F\u6DFB\u52A0 ${d}ReqModel`))),A.includes(`export interface ${d}ResModel {`)?console.log(t.yellowBright(`\u3010warning\u3011./${i}/models.ts \u5DF2\u5B58\u5728 ${d}ResModel`)):L.length&&(a.appendFileSync(c.join(n,`./${i}/models.ts`),L.join(`
6
+ `)),console.log(t.greenBright(`\u3010success\u3011./${i}/models.ts \u6210\u529F\u6DFB\u52A0 ${d}ResModel`)));const z=[o.title&&` /** ${o.title} */`,` ${s}(${S.length?`params: M.${d}ReqModel`:""}) {`,` return axios.${o.method.toLowerCase()}<ApiResponse<${L.length?`M.${d}ResModel`:"any"}>>(`,` \`\${ApiPrefix}/${o.path}\`,`,S.length&&` ${["post","put","patch"].includes(o.method.toLowerCase())?"params":"{ params }"},`," );"," },"].filter(Boolean);/^[a-zA-Z]+$/.test((o.method||"").trim())||console.log(t.yellowBright(`\u3010warning\u3011\u63A5\u53E3\u8BF7\u6C42\u7C7B\u578B\u5F02\u5E38\uFF0C\u8BF7\u624B\u52A8\u8865\u5168 method\uFF1A${o.method} path: ${o.path} methodId: ${this.config.methodId} projectId: ${this.config.projectId}`));try{const I=a.readFileSync(c.join(n,i,"api.ts")).toString(),y=I.split(`
7
+ `);if(I.includes(` ${s}(`)){const F=y.findIndex(M=>M.includes(` ${s}(`)),T=y.findIndex((M,k)=>k>F&&M===" },");console.log(t.yellowBright([`\u3010warning\u3011./${i}/api.ts \u5DF2\u5B58\u5728api`,...y.slice(F,T+1).map(M=>` ${M}`)].join(`
8
+ `))),console.log(t.yellowBright(`\u3010warning\u3011\u5F53\u524D\u9700\u8981\u751F\u6210\u7684 path \u4E3A ${o.path}, methodName \u4E3A ${s}`))}else y.splice(y.map(F=>F.includes("}")).lastIndexOf(!0),0,z.join(`
9
+ `)),a.writeFileSync(c.join(n,`./${i}/api.ts`),y.join(`
10
+ `)),console.log(t.greenBright(`\u3010success\u3011./${i}/api.ts \u6210\u529F\u6DFB\u52A0 ${s}`))}catch(I){a.writeFileSync(c.join(n,`./${i}/api.ts`),["import axios from 'axios';","","import * as M from './models';","import { ApiResponse } from '../responseModel';","import { ApiPrefix } from '../apiPrefix';","","export * from './models';","",`export const ${j(i)}Api = {`,...z,"};",""].join(`
11
+ `)),console.log(t.greenBright(`\u3010success\u3011./${i}/api.ts \u6210\u529F\u6DFB\u52A0 ${s}`));const y=a.readFileSync(c.join(n,"index.ts")).toString();if(!y.includes(`export * from './${i}/api'`)){const F=y.split(`
12
+ `);F.push(`export * from './${i}/api';`);const T=F.slice(1).filter(Boolean);T.sort((M,k)=>M.localeCompare(k)),a.writeFileSync(c.join(n,"index.ts"),[F[0]||"","",...T,""].join(`
13
+ `))}}})})}}({api:g.api,creatBaseFile:m.creatBaseFile||!0,methodId:f,customMethodName:e,outputPath:g.outputPath||"./src/apis",projectId:m.projectId,branchId:+m.branchId,outputDirName:m.outputDirName||"",apiBaseName:m.apiBaseName||"",ignoreParamsDTO:m.ignoreParamsDTO||[],deleteParentDTO:m.deleteParentDTO||[]})}else console.log(q.red(`\u3010error\u3011config \u914D\u7F6E\u6587\u4EF6\u4E2D projects \u672A\u5305\u542B\u4F20\u5165\u7684 projectId ${h}`))}),v.parse()});
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "sy-api-pro",
3
- "version": "0.0.9",
3
+ "version": "0.1.0",
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
  },
@@ -26,15 +26,15 @@
26
26
  },
27
27
  "description": "...",
28
28
  "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"
29
+ "axios": "^0.26.1",
30
+ "chalk": "4.1.2",
31
+ "commander": "^9.1.0",
32
+ "ts-node": "^10.7.0",
33
+ "typescript": "^4.6.3",
34
+ "@types/node": "^17.0.23"
35
35
  },
36
36
  "devDependencies": {
37
37
  "rollup-plugin-terser": "^7.0.2",
38
- "vite": "^2.7.10"
38
+ "vite": "^2.9.1"
39
39
  }
40
40
  }
File without changes
File without changes
@@ -2,9 +2,12 @@ import axios, { AxiosResponse } from 'axios';
2
2
 
3
3
  import { ApiPrefix } from './apiPrefix';
4
4
 
5
- axios.interceptors.request.use(config => config, error => Promise.reject(error));
5
+ axios.interceptors.request.use(config => {
6
+ return config;
7
+ }, error => Promise.reject(error));
8
+
6
9
  axios.interceptors.response.use((response: AxiosResponse) => {
7
- if (!response.config.url?.startsWith(ApiPrefix)) return;
10
+ if (!response.config.url?.startsWith(ApiPrefix)) return response;
8
11
  //
9
12
  // if (response.data?.success) {
10
13
  // return response;
@@ -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
- }