mirror of
https://github.com/tiennm99/is-a-good-dev.git
synced 2026-10-12 18:16:25 +00:00
Create raw-api.js
This commit is contained in:
1 parent
600097c976
commit
fd092fe6fa
1 file changed
+45
@@ -0,0 +1,45 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const directoryPath = path.join(__dirname, "../sub-logs");
|
||||
|
||||
let combinedArray = [];
|
||||
|
||||
fs.readdir(directoryPath, function (err, files) {
|
||||
if(err) throw err;
|
||||
|
||||
function removeValue(value, index, arr) {
|
||||
if(value === "reserved") {
|
||||
arr.splice(index, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
files.filter(removeValue);
|
||||
|
||||
files.forEach(function (file) {
|
||||
const filePath = path.join(directoryPath, file);
|
||||
|
||||
fs.readFile(filePath, "utf8", (err, data) => {
|
||||
if(err) throw err;
|
||||
|
||||
const dataArray = [JSON.parse(data)];
|
||||
|
||||
for(const item of dataArray) {
|
||||
delete item.owner.email;
|
||||
|
||||
item.domain = path.parse(file).name + ".is-a-good.dev";
|
||||
}
|
||||
|
||||
combinedArray = combinedArray.concat(dataArray);
|
||||
|
||||
if(combinedArray.length === files.length) {
|
||||
fs.writeFile("raw-api/index.json", JSON.stringify(combinedArray), (err) => {
|
||||
if(err) throw err;
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user