25 lines
696 B
JavaScript
25 lines
696 B
JavaScript
|
const fs = require('fs');
|
||
|
const path = require('path');
|
||
|
|
||
|
/**
|
||
|
* Loads modules from the plugins folder.
|
||
|
* Will expose the plugin on the event bus.
|
||
|
* @example
|
||
|
*/
|
||
|
class PluginLoader {
|
||
|
constructor(){
|
||
|
this.plugins = {};
|
||
|
}
|
||
|
|
||
|
async loadFromFolder() {
|
||
|
const dirList = fs.readdirSync(path.resolve(__dirname, "../plugins"));
|
||
|
for (let file in dirList) {
|
||
|
console.log(" - Found plugin: " + dirList[file])
|
||
|
const pluginName = dirList[file].replace('.js', '');
|
||
|
const module = require("../plugins/" + dirList[file]);
|
||
|
this.plugins = {...this.plugins, [pluginName]: module};
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = PluginLoader;
|