1 files changed, 30 insertions, 23 deletions
diff --git a/src/util/plugin/PluginLoader.ts b/src/util/plugin/PluginLoader.ts
index eadfb912..b46ef269 100644
--- a/src/util/plugin/PluginLoader.ts
+++ b/src/util/plugin/PluginLoader.ts
@@ -6,27 +6,34 @@ const root = process.env.PLUGIN_LOCATION || "../plugins";
let pluginsLoaded = false;
export class PluginLoader {
- public static loadPlugins() {
+ public static loadPlugins() {
+ console.log(`Plugin root directory: ${path.resolve(root)}`);
+ const dirs = fs.readdirSync(root).filter((x) => {
+ try {
+ fs.readdirSync(path.join(root, x));
+ return true;
+ } catch (e) {
+ return false;
+ }
+ });
+ console.log(dirs);
+ dirs.forEach(async (x) => {
+ let modPath = path.resolve(path.join(root, x));
+ console.log(`Trying to load plugin: ${modPath}`);
+ const manifest = require(path.join(modPath, "plugin.json")) as PluginManifest;
+ console.log(
+ `Plugin info: ${manifest.name} (${manifest.id}), written by ${manifest.authors}, available at ${manifest.repository}`
+ );
+ const module_ = require(path.join(modPath, "dist", "index.js")) as Plugin;
+ try {
+ await module_.init();
+ module_.emit("loaded");
+ } catch (error) {
+ module_.emit("error", error);
+ }
+ });
- console.log(`Plugin root directory: ${path.resolve(root)}`);
- const dirs = fs.readdirSync(root).filter(x => {
- try {
- fs.readdirSync(path.join(root, x));
- return true;
- } catch (e) {
- return false;
- }
- });
- console.log(dirs)
- dirs.forEach(x=>{
- let modPath = path.resolve(path.join(root, x));
- console.log(`Trying to load plugin: ${modPath}`)
- const manifest = require(path.join(modPath, "plugin.json")) as PluginManifest;
- console.log(`Plugin info: ${manifest.name} (${manifest.id}), written by ${manifest.authors}, available at ${manifest.repository}`)
- const module_ = require(path.join(modPath, "dist", "index.js")) as Plugin;
- module_.onPluginLoaded();
- })
- //
- //module_.pluginPath =
- }
-}
\ No newline at end of file
+ //
+ //module_.pluginPath =
+ }
+}
|