From 95781d7b0d507da4741a566b001d541f9e6a5ddf Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Sun, 9 May 2021 20:12:49 +0200 Subject: [PATCH] Move header.json to package.json for node projects --- modules/hello_world/header.json | 8 -------- modules/hello_world/package.json | 12 ++++++++++++ src/module_manager.js | 27 +++++++++++++++++++-------- 3 files changed, 31 insertions(+), 16 deletions(-) delete mode 100644 modules/hello_world/header.json create mode 100644 modules/hello_world/package.json diff --git a/modules/hello_world/header.json b/modules/hello_world/header.json deleted file mode 100644 index c7c70c4..0000000 --- a/modules/hello_world/header.json +++ /dev/null @@ -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" -} diff --git a/modules/hello_world/package.json b/modules/hello_world/package.json new file mode 100644 index 0000000..d28cc3c --- /dev/null +++ b/modules/hello_world/package.json @@ -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" +} diff --git a/src/module_manager.js b/src/module_manager.js index 4a00ae3..c288928 100644 --- a/src/module_manager.js +++ b/src/module_manager.js @@ -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];