Files
TsxVueClassApi/bin/service-code-generation/utils/ReadApiList.js
2024-09-27 00:48:07 +08:00

61 lines
1.5 KiB
JavaScript

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