Add required module checks
Checks for modules that are required by the server before startup.
This commit is contained in:
parent
6381f4723f
commit
875e043186
1 changed files with 31 additions and 2 deletions
33
index.js
33
index.js
|
@ -3,6 +3,15 @@ fs = require("fs"),
|
||||||
chalk = require("chalk"),
|
chalk = require("chalk"),
|
||||||
config = require("./config/config.json"),
|
config = require("./config/config.json"),
|
||||||
emoji = require("./misc/emoji_list.json");
|
emoji = require("./misc/emoji_list.json");
|
||||||
|
class reqMod {
|
||||||
|
constructor(name, status) {
|
||||||
|
this.name = name;
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const requiredModules = [
|
||||||
|
new reqMod("handle_console", false)
|
||||||
|
];
|
||||||
global.actualDir = __dirname;
|
global.actualDir = __dirname;
|
||||||
global.internals = {
|
global.internals = {
|
||||||
version:"Open Source",
|
version:"Open Source",
|
||||||
|
@ -34,6 +43,12 @@ fs.readFile('./misc/ascii.txt', function(err, data) {
|
||||||
if (files[i].includes(".js")) {
|
if (files[i].includes(".js")) {
|
||||||
console.log(`[Modules] Found module ${files[i].toString()}`);
|
console.log(`[Modules] Found module ${files[i].toString()}`);
|
||||||
global.modules[files[i].toString().replace(".js", "")] = require(`./modules/${files[i].toString()}`);
|
global.modules[files[i].toString().replace(".js", "")] = require(`./modules/${files[i].toString()}`);
|
||||||
|
// Loop through and set the required modules flags
|
||||||
|
for (var i1 = 0; i1 < requiredModules.length; i1++) {
|
||||||
|
if (global.modules[files[i].toString().replace(".js", "")].MOD_FUNC == requiredModules[i1].name) {
|
||||||
|
requiredModules[i1].status = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
// We want to find out what the request handler module is
|
// We want to find out what the request handler module is
|
||||||
if (global.modules[files[i].toString().replace(".js", "")].MOD_FUNC == "handle_requests") {
|
if (global.modules[files[i].toString().replace(".js", "")].MOD_FUNC == "handle_requests") {
|
||||||
// Set reqhandler to the request handler for easy getting
|
// Set reqhandler to the request handler for easy getting
|
||||||
|
@ -48,8 +63,22 @@ fs.readFile('./misc/ascii.txt', function(err, data) {
|
||||||
console.log(chalk.bgRed(` ! [Modules] ${err} ! `));
|
console.log(chalk.bgRed(` ! [Modules] ${err} ! `));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
global.modules.consoleHelper.printInfo(emoji.wave, "Starting Revolution...");
|
// Check if all the required modules flags are set
|
||||||
server();
|
let allRequiredExist = [];
|
||||||
|
for (var i = 0; i < requiredModules.length; i++) {
|
||||||
|
if (requiredModules[i].status) {
|
||||||
|
allRequiredExist.push(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (allRequiredExist.length !== requiredModules.length) {
|
||||||
|
// Exit if all required modules are not found
|
||||||
|
console.log("[Modules] All required modules could not be found.");
|
||||||
|
console.log("[Modules] Server will not start until all required modules are found.");
|
||||||
|
process.exit(1);
|
||||||
|
} else {
|
||||||
|
global.modules.consoleHelper.printInfo(emoji.wave, "Starting Revolution...");
|
||||||
|
server();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue