yasd/apps/server/lib/PluginLoader.js

25 lines
696 B
JavaScript
Raw Permalink Normal View History

2022-04-29 11:21:51 -04:00
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;