first commit
This commit is contained in:
1
bin/service-code-generation/utils/.pydio
Normal file
1
bin/service-code-generation/utils/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
7fcbe2a8-4ef1-42fd-8123-b5ed331cbd41
|
||||
59
bin/service-code-generation/utils/File.js
Normal file
59
bin/service-code-generation/utils/File.js
Normal file
@@ -0,0 +1,59 @@
|
||||
const { writeFileSync, existsSync } = require("fs");
|
||||
const config = require("../config");
|
||||
|
||||
class File {
|
||||
|
||||
createdService(ServiceName, ServiceMethods) {
|
||||
let fullPath = `${config.outPutServicePath}\\${ServiceName}.service.ts`
|
||||
if (!existsSync(fullPath)) {
|
||||
let mArray = Array.from(ServiceMethods, ([name, value]) => ({ name, value }));
|
||||
writeFileSync(fullPath, this.stripIndent`
|
||||
// @ts-nocheck
|
||||
import { GET, Mapper, POST, PUT, DELETE } from "@ann/Http.annotation";
|
||||
import { property, defaultValue, deserialize } from "@ann/JsonToClass";
|
||||
|
||||
// 建议用工具json-class-desktop生成这个类 类型
|
||||
export class ResponseType {
|
||||
@property("id")
|
||||
user_id!: number;
|
||||
}
|
||||
|
||||
export class ${ServiceName}Service {
|
||||
${mArray.map(v => {
|
||||
return `
|
||||
@GET()
|
||||
@Mapper(ResponseType)
|
||||
public async ${v.name} (params: object): Promise<ResponseType[]> {}
|
||||
`
|
||||
}).toString().replaceAll(",", "")
|
||||
}
|
||||
}
|
||||
`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
stripIndent(template, ...expressions) {
|
||||
let result = template.reduce((prev, next, i) => {
|
||||
let expression = expressions[i - 1];
|
||||
if ( Array.isArray(expression)) {
|
||||
expression = expression.join('');
|
||||
}
|
||||
return prev + expression + next;
|
||||
});
|
||||
|
||||
const match = result.match(/^[^\S\n]*(?=\S)/gm);
|
||||
const indent = match && Math.min(...match.map(el => el.length));
|
||||
|
||||
if (indent) {
|
||||
const regexp = new RegExp(`^.{${indent}}`, 'gm');
|
||||
result = result.replace(regexp, '');
|
||||
}
|
||||
|
||||
result = result.replace(/^[^\S\n]+/gm, ' ');
|
||||
result = result.trim();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new File
|
||||
61
bin/service-code-generation/utils/ReadApiList.js
Normal file
61
bin/service-code-generation/utils/ReadApiList.js
Normal file
@@ -0,0 +1,61 @@
|
||||
const { createReadStream } = require('fs')
|
||||
|
||||
class ReadApiList {
|
||||
apiListPath = "";
|
||||
lineLength = 0;
|
||||
textArr = [];
|
||||
lineBuffer = Buffer.alloc(4096);
|
||||
text = "";
|
||||
|
||||
constructor(path) {
|
||||
this.apiListPath = path
|
||||
}
|
||||
|
||||
getFileList() {
|
||||
this.text = createReadStream(this.apiListPath)
|
||||
return new Promise((s, e) => {
|
||||
this.textArr = [];
|
||||
let status = false
|
||||
this.text.on('data', (data) => {
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
if (data[i] == 10 || data[i] == 13) {
|
||||
if (data[i] == 10) {
|
||||
try {
|
||||
var line = this.lineBuffer.slice(0, this.lineLength);
|
||||
if (line.length != 0) {
|
||||
let str = line.toString('utf8')
|
||||
.replace(/^\s+|\s+$/g, '')
|
||||
.replace(/\'/g, "")
|
||||
.replace(/,/g, "")
|
||||
|
||||
if (str.includes("start -")) {
|
||||
status = true
|
||||
continue;
|
||||
}
|
||||
if (str.includes("end -")) {
|
||||
status = false
|
||||
break;
|
||||
}
|
||||
|
||||
if (status) {
|
||||
// console.log("str: ", str.split(":"))
|
||||
this.textArr.push(str);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
this.lineLength = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.lineBuffer[this.lineLength] = data[i];
|
||||
this.lineLength++;
|
||||
}
|
||||
}
|
||||
|
||||
s(this.textArr)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ReadApiList
|
||||
Reference in New Issue
Block a user