Commit 446b5b76 authored by insert's avatar insert

Automatically installs dependencies from npm

parent dead5522
......@@ -4,9 +4,7 @@ let fortniteAPI = new Fortnite([
"kerchow74",
"MzRhMDJjZjhmNDQxNGUyOWIxNTkyMTg3NmRhMzZmOWE6ZGFhZmJjY2M3Mzc3NDUwMzlkZmZlNTNkOTRmYzc2Y2Y=",
"ZWM2ODRiOGM2ODdmNDc5ZmFkZWEzY2IyYWQ4M2Y1YzY6ZTFmMzFjMjExZjI4NDEzMTg2MjYyZDM3YTEzZmM4NGQ="
], {
debug: true
});
]);
let connected = false;
......
const fs = require('fs');
const child_process = require('child_process');
const path = require('path');
var modules = {};
var commands = {};
......@@ -47,11 +49,13 @@ let index = path => {
};
core.reload = () => {
console.log("[INFO] Reloading...");
commands = {};
modules = {};
let mods = fs.readdirSync('./core');
let modules_missing = [];
mods.forEach(mod => {
if (mod == 'index.js') return;
if (mod == 'index.js' || mod == 'node_modules' || mod == 'package-lock.json') return;
try {
let path = `./core/${mod}/`;
let cmds = fs.readdirSync(path);
......@@ -74,9 +78,31 @@ core.reload = () => {
}, i.commands[n]);
});
} catch (e) {
console.error('[WARN] Failed to load module, ' + mod + '!');
console.error('[WARN] Failed to load module, ' + mod + ' with error: ' + e);
if ((''+e).includes('Cannot find module')) {
let module = /Error: Cannot find module '(.+?)'/.exec((''+e))[1];
console.log('[WARN] Node module missing, ' + module + '!');
modules_missing.push(module);
}
}
});
if (modules_missing.length == 0) return;
console.log("[INFO] Several modules are missing, installing them in 5 seconds! Exit if you do not want to proceed.");
setTimeout(() => {
modules_missing.forEach(module => {
try {
let res = child_process.execSync('npm i ' + module, {
cwd: path.resolve(__dirname)
});
console.log(res);
} catch (e) {
console.log('[WARN] Failed to install node module: ' + module + '!');
}
});
core.reload();
}, 5e3);
};
if (!fs.existsSync('./core/node_modules')) fs.mkdirSync('./core/node_modules');
core.reload();
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment