This commit is contained in:
编码猿
2025-08-29 22:07:01 +08:00
parent 08057d0276
commit dc70b5fc26
10 changed files with 169 additions and 56 deletions

View File

@@ -4,8 +4,10 @@ const config = require("../config");
class File {
createdService(ServiceName, ServiceMethods) {
let fullPath = `${config.outPutServicePath}\\${ServiceName}.service.ts`
if (!existsSync(fullPath)) {
console.log("ServiceName: ", ServiceName);
console.log("ServiceMethods: ", 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
@@ -29,7 +31,7 @@ class File {
}
}
`)
}
// }
}

View File

@@ -1,59 +1,55 @@
const { createReadStream } = require('fs')
class ReadApiList {
apiListPath = "";
lineLength = 0;
textArr = [];
lineBuffer = Buffer.alloc(4096);
text = "";
status = false;
lineBuffer = [];
lineLength = 0;
stream = null
constructor(path) {
this.apiListPath = path
this.stream = createReadStream(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, "")
return new Promise((resolve, reject) => {
this.stream.on('data', (data) => {
for (let i = 0; i < data.length; i++) {
const byte = data[i];
if (byte === 10 || byte === 13) { // 处理 \n 和 \r
if (this.lineLength > 0) {
const line = Buffer.from(this.lineBuffer.slice(0, this.lineLength)).toString('utf8');
const cleanedLine = line.trim().replace(/'|,/g, '');
if (str.includes("start -")) {
status = true
continue;
}
if (str.includes("end -")) {
status = false
break;
}
if (cleanedLine.includes("start -")) {
this.status = true;
} else if (cleanedLine.includes("end -")) {
this.status = false;
if (status) {
// console.log("str: ", str.split(":"))
this.textArr.push(str);
}
}
} finally {
this.lineLength = 0;
// 去除被注释的key代码
} else if (this.status && !cleanedLine.includes("//")) {
this.textArr.push(cleanedLine);
}
}
this.lineLength = 0; // 重置行缓冲区
} else {
this.lineBuffer[this.lineLength] = data[i];
if (this.lineLength >= this.lineBuffer.length) {
this.lineBuffer.push(byte);
} else {
this.lineBuffer[this.lineLength] = byte;
}
this.lineLength++;
}
}
});
s(this.textArr)
})
this.stream.on('end', () => {
resolve(this.textArr);
});
this.stream.on('error', (err) => {
reject(err);
});
})
}
}