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,18 +16,29 @@ class ModuleManager {
scanModules() {
console.log("Scanning for modules");
fs.readdirSync(process.env.MODULES_DIR).forEach(file => {
let rawData = fs.readFileSync(process.env.MODULES_DIR + "/" + file + "/header.json");
let header = JSON.parse(rawData);
let path = process.env.MODULES_DIR + "/" + file + "/package.json";
this.moduleList[header.prefix] = new Module(header.name,
header.description,
header.prefix,
header.flavor,
process.env.MODULES_DIR + "/" + file + "/" + header.entrypoint,
header.version);
if(fs.existsSync(path)) {
this.loadNodeModule(path);
}
});
}
loadNodeModule(path) {
let rawData = fs.readFileSync(path);
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,
header.description,
header.prefix,
"node",
entrypoint,
header.version);
}
execute(prefix, message) {
let module = this.moduleList[prefix];