Initial Code Upload
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
module.exports = {
|
||||||
|
database:{
|
||||||
|
/*
|
||||||
|
Here is an example structure of the config file
|
||||||
|
You can ofcourse change anything here to suit your needs
|
||||||
|
This structure is useful if you are using a mysql/mariadb database for example
|
||||||
|
*/
|
||||||
|
host:"", // Server IP and port if you have set a different port
|
||||||
|
username:"", // Username for the database user
|
||||||
|
password:"", // Password for the database user
|
||||||
|
database:"" // Name of the database
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
// Loading required packages
|
||||||
|
require("./requires.js")
|
||||||
|
console.log(start);
|
||||||
|
|
||||||
|
|
||||||
|
// Initialising map to be used to store the functionality later on for reloadability
|
||||||
|
mapFunctions = new Map()
|
||||||
|
|
||||||
|
|
||||||
|
// Loading the Function Map
|
||||||
|
var path = `${mainDir}/modules`
|
||||||
|
var folders = fs.readdirSync(path).filter(function (file) {
|
||||||
|
return fs.statSync(path+'/'+file).isDirectory();
|
||||||
|
});
|
||||||
|
folders.forEach(element => {
|
||||||
|
var commandFiles = fs.readdirSync(`${mainDir}/modules/${element}`).filter(file => file.endsWith('.js') && !file.startsWith("index"));
|
||||||
|
for (const file of commandFiles) {
|
||||||
|
delete require.cache[require.resolve(`${mainDir}/modules/${element}/${file}`)];
|
||||||
|
const command = require(`${mainDir}/modules/${element}/${file}`);
|
||||||
|
mapFunctions.set(command.name, command);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// The startup information for the project, here you can add stuff that might be nice to see when the app starts
|
||||||
|
mapFunctions.get("Startup_function").function()
|
||||||
|
console.log("------------------------------------ Status ------------------------------------");
|
||||||
|
console.log(__dirname);
|
||||||
|
console.log(platform);
|
||||||
|
console.log(`The Startup took ${new Date() - start}ms`)
|
||||||
|
console.log(`${mapFunctions.size} Function modules loaded`);
|
||||||
|
console.log("--------------------------------------------------------------------------------");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// --------------------------------------------------------- CLI COMMANDS --------------------------------------------------------- //
|
||||||
|
|
||||||
|
const rl = readline.createInterface({
|
||||||
|
input: process.stdin,
|
||||||
|
output: process.stdout
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
rl.on("line", data =>{
|
||||||
|
const args = data.trim().split(" ");
|
||||||
|
const command = args.shift().toLowerCase();
|
||||||
|
mapFunctions.get("cliCommands").function(command, args)
|
||||||
|
})
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
module.exports = {
|
||||||
|
name:"example", // Unique name for our function that will later be used to get the function from the map via "mapFunctions.get("example").function()"
|
||||||
|
async function(randomParameter){
|
||||||
|
// Here we put a simple console.log to show how the system works
|
||||||
|
// This function will be called from the @startup.js function in the utility folder
|
||||||
|
console.log(`\n------------\nThis is the example function called by the ${randomParameter} function\n------------\n`);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
module.exports = {
|
||||||
|
name:"Startup_function",
|
||||||
|
async function(){
|
||||||
|
// Put any code here that you want to be executed on startup
|
||||||
|
|
||||||
|
// We are now calling the example function from the example folder
|
||||||
|
mapFunctions.get("example").function("Startup")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
module.exports = {
|
||||||
|
name:"cliCommands",
|
||||||
|
async function(command, args){
|
||||||
|
switch(command){
|
||||||
|
case "exit":
|
||||||
|
process.exit(1);
|
||||||
|
break;
|
||||||
|
case "reload":
|
||||||
|
// Reloading the Function Map
|
||||||
|
var path = `${mainDir}/modules`
|
||||||
|
var folders = fs.readdirSync(path).filter(function (file) {
|
||||||
|
return fs.statSync(path+'/'+file).isDirectory();
|
||||||
|
});
|
||||||
|
folders.forEach(element => {
|
||||||
|
var commandFiles = fs.readdirSync(`${path}/${element}`).filter(file => file.endsWith('.js') && !file.startsWith("index"));
|
||||||
|
for (const file of commandFiles) {
|
||||||
|
delete require.cache[require.resolve(`${path}/${element}/${file}`)];
|
||||||
|
const command = require(`${path}/${element}/${file}`);
|
||||||
|
mapFunctions.set(command.name, command);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.log(`Reloaded ${mapEvents.size + mapFunctions.size} modules`)
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.log("This is not a recognised command");
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+2354
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "locationsystem",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"start": "node index",
|
||||||
|
"run": "node index"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"@socket.io/admin-ui": "^0.2.0",
|
||||||
|
"express": "^4.17.1",
|
||||||
|
"mysql": "^2.18.1",
|
||||||
|
"socket.io": "^4.2.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// Here you can define all the packages that you want to use
|
||||||
|
// You can also define variables that you want to be able to use in your entire project, like platform or mainDir in this example
|
||||||
|
// Make sure to define them like these examples here, as they will then be available as global variables throughout your entire project
|
||||||
|
start = new Date()
|
||||||
|
platform = process.platform
|
||||||
|
mainDir = __dirname
|
||||||
|
fs = require("fs")
|
||||||
|
readline = require("readline")
|
||||||
|
config = require("./config/config")
|
||||||
Reference in New Issue
Block a user