first commit
This commit is contained in:
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