Move header.json to package.json for node projects

This commit is contained in:
Tanguy Herbron 2021-05-09 20:12:49 +02:00
parent a4bf401f32
commit 95781d7b0d
3 changed files with 31 additions and 16 deletions

View File

@ -1,8 +0,0 @@
{
"name": "Hello world",
"description": "Hello world, example module for embeded messages",
"prefix": "!hello",
"flavor": "node",
"entrypoint": "index.js",
"version": "0.0.1"
}

View File

@ -0,0 +1,12 @@
{
"name": "hello-world",
"version": "0.0.1",
"description": "Hello world, example module for embeded messages",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Tanguy Herbron",
"license": "MIT",
"prefix": "!hello"
}

View File

@ -16,16 +16,27 @@ class ModuleManager {
scanModules() { scanModules() {
console.log("Scanning for modules"); console.log("Scanning for modules");
fs.readdirSync(process.env.MODULES_DIR).forEach(file => { fs.readdirSync(process.env.MODULES_DIR).forEach(file => {
let rawData = fs.readFileSync(process.env.MODULES_DIR + "/" + file + "/header.json"); let path = process.env.MODULES_DIR + "/" + file + "/package.json";
if(fs.existsSync(path)) {
this.loadNodeModule(path);
}
});
}
loadNodeModule(path) {
let rawData = fs.readFileSync(path);
let header = JSON.parse(rawData); let header = JSON.parse(rawData);
let modulePath = path.substring(0, path.lastIndexOf('/'));
let entrypoint = modulePath + "/" + header.main;
this.moduleList[header.prefix] = new Module(header.name, this.moduleList[header.prefix] = new Module(header.name,
header.description, header.description,
header.prefix, header.prefix,
header.flavor, "node",
process.env.MODULES_DIR + "/" + file + "/" + header.entrypoint, entrypoint,
header.version); header.version);
});
} }
execute(prefix, message) { execute(prefix, message) {