-
Notifications
You must be signed in to change notification settings - Fork 34
/
build-indexes.js
90 lines (70 loc) · 2.46 KB
/
build-indexes.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const fs = require("fs"),
path = require("path"),
index = "index.ts";
function buildMutators(dirname, packetsPath) {
const files = fs.readdirSync(dirname);
let includes = "",
exp = "";
files.forEach((file) => {
const fullPath = `${dirname}\\${file}`;
if (file !== index && fs.existsSync(fullPath) && path.extname(file) === ".ts") {
const baseName = path.basename(file, path.extname(file));
const packetName = baseName.replace("Mutator", "");
includes = `${includes}
import ${baseName} from "./${baseName}";
import ${packetName} from "${packetsPath}/${packetName}";`;
exp = `${exp} [${baseName}.prototype, ${packetName}],\n`;
}
});
const text = `${includes}\n
export default [
${exp}
];
`;
fs.writeFileSync(path.join(dirname, index), text);
}
function buildPackets(dirname) {
const files = fs.readdirSync(dirname);
let includes = "";
let exp = "";
files.forEach((file) => {
const fullPath = `${dirname}\\${file}`;
if (file !== index && fs.existsSync(fullPath) && path.extname(file) === ".ts") {
const baseName = path.basename(file, path.extname(file));
includes = `${includes}import ${baseName} from "./${baseName}";\n`;
exp = `${exp} ${baseName},\n`;
}
});
const text = `${includes.trim()}\n
export {
${exp}
};
`;
fs.writeFileSync(path.join(dirname, index), text);
}
function buildCommands(dirname) {
const files = fs.readdirSync(dirname);
let includes = "";
let exp = "";
files.forEach((file) => {
const fullPath = `${dirname}\\${file}`;
if (file !== index && fs.existsSync(fullPath) && path.extname(file) === ".ts" && file.startsWith("Command")) {
const baseName = path.basename(file, path.extname(file));
let key = baseName.substr(7);
key = key.charAt(0).toLowerCase() + key.slice(1);
includes = `${includes}import ${baseName} from "./${baseName}";\n`;
exp = `${exp} ${key}: ${baseName}.prototype,\n`;
}
});
const text = `${includes}\n
export default {
${exp}
};
`;
fs.writeFileSync(path.join(dirname, index), text);
}
buildMutators(path.join(__dirname, "src", "network", "mutators", "game"), "../../incoming/game");
buildMutators(path.join(__dirname, "src", "network", "mutators", "login"), "../../incoming/login");
buildPackets(path.join(__dirname, "src", "network", "incoming", "game"));
buildPackets(path.join(__dirname, "src", "network", "incoming", "login"));
buildCommands(path.join(__dirname, "src", "commands"));