-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapData.cjs
56 lines (43 loc) · 1.63 KB
/
mapData.cjs
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
56
const fs = require("fs");
const { dirname, join } = require("path")
const convertDir = (dir, to) => {
let items = fs.readdirSync(dir);
let o = {};
for(let item of items) {
//console.log(">>> " + item);
let name = item.replace(".json", "");
o[name] = JSON.parse(fs.readFileSync(dir + "/" + item));
}
if(!fs.existsSync(dirname(to)))
fs.mkdirSync(dirname(to), { recursive: true });
fs.writeFileSync(to + ".json", JSON.stringify(o, 2));
};
let root = "./_minecraft/1.20.1/";
let assets = "assets/minecraft";
let data = "data/minecraft";
const jsonDir = (path, to) => {
if(fs.existsSync(path)) {
convertDir(path, to);
//fs.rm(path, { recursive: true }, () => {});
}
};
const processDir = (outBase, inBase, path) => {
console.log("> " + path);
let items = fs.readdirSync(join(inBase, path), { withFileTypes: true });
if(items.every(x => x.isFile() && x.name.endsWith(".json")))
return jsonDir(join(inBase, path), join(outBase, path));
for(let item of items) {
if(item.isDirectory()) {
processDir(outBase, inBase, join(path, item.name));
} else {
let to = join(outBase, path, item.name);
if(!fs.existsSync(dirname(to)))
fs.mkdirSync(dirname(to), { recursive: true });
fs.copyFileSync(join(inBase, path, item.name), to);
}
}
};
processDir("./data", "./_minecraft/1.20.1/assets/minecraft", ".");
console.log("Cleaning up...");
fs.rm("./versions", { recursive: true }, () => console.log("1/2"));
fs.rm("./_minecraft", { recursive: true }, () => console.log("Done!"));