Move header.json to package.json for node projects
This commit is contained in:
parent
a4bf401f32
commit
95781d7b0d
@ -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"
|
||||
}
|
12
modules/hello_world/package.json
Normal file
12
modules/hello_world/package.json
Normal 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"
|
||||
}
|
@ -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];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user