summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2022-08-13 02:14:41 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2022-09-04 10:48:54 +0200
commitfc0465dee141ebbba68a65f4f71d315a7e9a2aed (patch)
tree13897bd1c8a0d095799d8b902295ec2b19b707ec
parentBasic client patching system (diff)
downloadserver-fc0465dee141ebbba68a65f4f71d315a7e9a2aed.tar.xz
feat(plugins): loader
-rw-r--r--src/util/plugin/Plugin.ts5
-rw-r--r--src/util/plugin/PluginLoader.ts32
-rw-r--r--src/util/plugin/PluginManifest.ts9
-rw-r--r--src/util/plugin/index.ts3
4 files changed, 49 insertions, 0 deletions
diff --git a/src/util/plugin/Plugin.ts b/src/util/plugin/Plugin.ts
new file mode 100644
index 00000000..246e9931
--- /dev/null
+++ b/src/util/plugin/Plugin.ts
@@ -0,0 +1,5 @@
+export class Plugin {
+    onPluginLoaded() {
+        console.log('no onpluginloaded!')
+    }
+}
\ No newline at end of file
diff --git a/src/util/plugin/PluginLoader.ts b/src/util/plugin/PluginLoader.ts
new file mode 100644
index 00000000..eadfb912
--- /dev/null
+++ b/src/util/plugin/PluginLoader.ts
@@ -0,0 +1,32 @@
+import path from "path";
+import fs from "fs";
+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(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
diff --git a/src/util/plugin/PluginManifest.ts b/src/util/plugin/PluginManifest.ts
new file mode 100644
index 00000000..b171956b
--- /dev/null
+++ b/src/util/plugin/PluginManifest.ts
@@ -0,0 +1,9 @@
+export class PluginManifest {
+    id: string;
+    name: string;
+    authors: string[];
+    repository: string;
+    license: string;
+	version: string // semver
+	versionCode: number // integer
+}
\ No newline at end of file
diff --git a/src/util/plugin/index.ts b/src/util/plugin/index.ts
new file mode 100644
index 00000000..c4c0c2ac
--- /dev/null
+++ b/src/util/plugin/index.ts
@@ -0,0 +1,3 @@
+export * from "./Plugin";
+export * from "./PluginLoader";
+export * from "./PluginManifest";