sy-api-pro 0.1.6 → 0.1.7

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 +6 -4
package/dist/index.umd.js CHANGED
@@ -1,13 +1,13 @@
1
- var L=(B,D,y)=>new Promise((P,x)=>{var a=m=>{try{u(y.next(m))}catch($){x($)}},p=m=>{try{u(y.throw(m))}catch($){x($)}},u=m=>m.done?P(m.value):Promise.resolve(m.value).then(a,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=>!n.includes(e.type)).map(e=>{if(e.id&&e.json){const s=e.json.split(`
2
- `);return s.forEach((t,o)=>{var h;const c=/(?<space>\s*)"(?<name>[a-zA-Z0-9]+)"\s?:\s*"(?<desc>.*)".*$/;if(c.test(t)){const{space:f,name:w,desc:_}=((h=c.exec(t))==null?void 0:h.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(c,`${f+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)}`})}}),a=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 m=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 c=o.body.branchList.find(f=>f.id===i);if(c)console.log(u.blueBright(`\u3010info\u3011\u6B63\u5728\u4F7F\u7528 branchName: ${c.name} branchId: ${i} methodId: ${d}`));else throw u.red(`\u3010error\u3011branchId ${i} \u4E0D\u5B58\u5728`);const h=yield y.default.get(`${n}/api/method/getMethodById?id=${d}`);this.apiList=[h.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{a.statSync(n,{bigint:!0})}catch(i){a.mkdirSync(n,{recursive:!0})}}creatBaseFile(){return L(this,null,function*(){const{outputPath:n}=this.config,i=p.join(__dirname,"../template/api"),l=a.readdirSync(i),e=a.readdirSync(n);for(const s of l)if(!e.includes(s))try{const d=a.readFileSync(p.join(i,s));a.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,g=>g.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,c=s(`${t}-`+o);try{a.statSync(p.join(i,t)).isDirectory()}catch(F){a.mkdirSync(p.join(i,t))}let h="";try{h=a.readFileSync(p.join(i,t,"models.ts")).toString()}catch(F){a.writeFileSync(p.join(i,`./${t}/models.ts`),"")}let f=[],w=[];try{f=(I=e.paramList)!=null&&I.length?[h?"":"/* ************************************************ */",`/** ${e.title} RequestModel */`,`export interface ${c}ReqModel {`,...x.getInterface({list:e.paramList||[],config:this.config}),"}",""]:[],w=(R=e.returnList)!=null&&R.length?[f.length?"":"/* ************************************************ */",`/** ${e.title} ResponseModel */`,`export interface ${c}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)}h.includes(`export interface ${c}ReqModel {`)?console.log(u.yellowBright(`\u3010warning\u3011./${t}/models.ts \u5DF2\u5B58\u5728 ${c}ReqModel`)):f.length&&(a.appendFileSync(p.join(i,`./${t}/models.ts`),f.join(`
5
- `)),console.log(u.greenBright(`\u3010success\u3011./${t}/models.ts \u6210\u529F\u6DFB\u52A0 ${c}ReqModel`))),h.includes(`export interface ${c}ResModel {`)?console.log(u.yellowBright(`\u3010warning\u3011./${t}/models.ts \u5DF2\u5B58\u5728 ${c}ResModel`)):w.length&&(a.appendFileSync(p.join(i,`./${t}/models.ts`),w.join(`
6
- `)),console.log(u.greenBright(`\u3010success\u3011./${t}/models.ts \u6210\u529F\u6DFB\u52A0 ${c}ResModel`)));const b=[e.title&&` /** ${e.title} */`,` ${o}(${f.length?`params: M.${c}ReqModel`:""}) {`,` return axios.${e.method.toLowerCase()}<ApiResponse<${w.length?`M.${c}ResModel`:"any"}>>(`,` \`\${ApiPrefix}/${e.path}\`,`,f.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=a.readFileSync(p.join(i,t,"api.ts")).toString(),g=F.split(`
7
- `);if(F.includes(` ${o}(`)){const j=g.findIndex(A=>A.includes(` ${o}(`)),N=g.findIndex((A,O)=>O>j&&A===" },");console.log(u.yellowBright([`\u3010warning\u3011./${t}/api.ts \u5DF2\u5B58\u5728api`,...g.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 g.splice(g.map(j=>j.includes("}")).lastIndexOf(!0),0,b.join(`
9
- `)),a.writeFileSync(p.join(i,`./${t}/api.ts`),g.join(`
10
- `)),console.log(u.greenBright(`\u3010success\u3011./${t}/api.ts \u6210\u529F\u6DFB\u52A0 ${o}`))}catch(F){a.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 g=a.readFileSync(p.join(i,"index.ts")).toString();if(!g.includes(`export * from './${t}/api'`)){const j=g.split(`
12
- `);j.push(`export * from './${t}/api';`);const N=j.slice(1).filter(Boolean);N.sort((A,O)=>A.localeCompare(O)),a.writeFileSync(p.join(i,"index.ts"),[j[0]||"","",...N,""].join(`
13
- `))}}})})}},$=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($.existsSync(l)||$.mkdirSync(l),$.existsSync(e))return console.log(E.yellowBright(`\u3010warning\u3011: ${e} \u914D\u7F6E\u6587\u4EF6\u5DF2\u5B58\u5728`));const s=$.readFileSync(S.join(__dirname,"../template/config/.api-config.ts"));$.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)=>{var c;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(h=>+h.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 m({api:t.api,creatBaseFile:(c=o.creatBaseFile)!=null?c:!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()});
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()});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sy-api-pro",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "main": "./bin/index.ts",
5
5
  "types": "./bin/model.d.ts",
6
6
  "bin": {
@@ -22,16 +22,18 @@
22
22
  "scripts": {
23
23
  "build": "vite build",
24
24
  "api": "ts-node src/index.ts create --config ./src/.api-config.ts --project-id 804",
25
+ "api2": "ts-node src/index.ts create --config ./src/.api-config.ts --project-id 801 -i 674266",
25
26
  "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"
27
+ "test:dist-create": "ts-node bin/index.ts create --config ./src/.api-config.ts --project-id 804",
28
+ "test:dist-create2": "ts-node bin/index.ts create --config ./src/.api-config.ts --project-id 801"
27
29
  },
28
30
  "description": "...",
29
31
  "dependencies": {
30
32
  "axios": "^0.26.1",
31
33
  "chalk": "4.1.2",
32
34
  "commander": "^9.1.0",
33
- "ts-node": "^10.7.0",
34
- "typescript": "^4.6.3",
35
+ "ts-node": "9.1.1",
36
+ "typescript": "4.9.4",
35
37
  "@types/node": "^17.0.23"
36
38
  },
37
39
  "devDependencies": {