-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
46 lines (40 loc) · 1.44 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const
path = require("path"),
fs = require("fs"),
sep = path.sep,
root = ["..", "..", "databases"].join(sep);
index = {},
out = { index:[] };
fs.readdirSync(root).forEach(file => {
let
fileStat = fs.statSync(root + sep + file);
if (fileStat.isDirectory()) {
const
subpath = root + sep + file + sep,
indexFile = subpath + "index.json",
index = {
entries:[]
};
fs.readdirSync(subpath).forEach(file => {
let
fileStat = fs.statSync(subpath + sep + file);
if (fileStat.isDirectory()) {
const
tableFile = subpath + sep + file + sep + "table.json";
if (fs.existsSync(tableFile)) {
const
data = fs.readFileSync(tableFile, { encoding: "utf8", flag: "r" });
try {
let jsonData = JSON.parse(data);
fs.writeFileSync(tableFile, JSON.stringify(jsonData,null,"\t"));
index.entries.push({ path:file, meta:jsonData.meta });
} catch (e) {
console.warn("Can't parse file",tableFile);
}
}
}
});
fs.writeFileSync(indexFile, JSON.stringify(index,null,"\t"));
}
});
console.log("Table JSON prettified and database indexes rebuilt.");