-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathloader.js
55 lines (41 loc) · 1.24 KB
/
loader.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
47
48
49
50
51
52
53
54
55
"use strict";
process.env.NODE_NO_WARNINGS = "1";
// Dependencies
const path = require("path")
const fs = require("fs")
// Variables
const excluded = ["_archive", "_libraries", "test.lua"]
// Functions
function getLuaFiles(dirPath){
const files = []
function readDirR(dirPath){
const entries = fs.readdirSync(dirPath, { withFileTypes: true })
entries.map((entry)=>{
const fullPath = path.join(dirPath, entry.name)
if(entry.isDirectory()){
readDirR(fullPath)
}else if(path.extname(fullPath) === ".lua" && !excluded.includes(fullPath.split("\\")[1])){
files.push(fullPath)
}
})
}
readDirR(dirPath)
return files
}
// Main
const results = []
const files = getLuaFiles("./scripts")
for( const f of files ){
const read = fs.readFileSync(f, "utf8")
try{
var data = JSON.parse(read.slice(4, read.indexOf("]]"), { logLevel: "error" }))
data.fileSource = f.replace(/\\/g, "/")
results.push(data)
}catch(err){
console.log(`Couldn't parse ${f}`)
}
}
// console.log(yaml.parse(b.slice(4, b.indexOf("]]")-1)))
fs.writeFileSync("./database.json", JSON.stringify(results, null, 2), "utf8")
process.on("warning", ()=>{return})
process.on("uncaughtExceptionMonitor", ()=>{return})