From feca7a5d620362d028c8f31353b0c996693697e3 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Sat, 27 Aug 2022 07:07:05 +0200 Subject: Merge 'webrtc' into 'dev/staging_webrtc' --- src/util/plugin/PluginLoader.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/util/plugin/PluginLoader.ts (limited to 'src/util/plugin/PluginLoader.ts') diff --git a/src/util/plugin/PluginLoader.ts b/src/util/plugin/PluginLoader.ts new file mode 100644 index 00000000..000f3345 --- /dev/null +++ b/src/util/plugin/PluginLoader.ts @@ -0,0 +1,39 @@ +import fs from "fs"; +import path from "path"; +import { Plugin, PluginManifest } from "./"; + +const root = process.env.PLUGIN_LOCATION || "../plugins"; + +let pluginsLoaded = false; +export class PluginLoader { + 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); + } + }); + + // + //module_.pluginPath = + } +} -- cgit 1.5.1