summary refs log tree commit diff
path: root/src/util/plugin
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2022-08-13 08:54:50 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2022-09-04 10:48:54 +0200
commit87d6a6778c6d502df511b639375fa219ac8713c6 (patch)
tree5da20d24c2f7fd17036e7ce67c72a25ec6c7bc36 /src/util/plugin
parentfeat(plugins): event system (diff)
downloadserver-87d6a6778c6d502df511b639375fa219ac8713c6.tar.xz
Update plugin loading, update example plugin, add ci task for testing if builds work
Diffstat (limited to 'src/util/plugin')
-rw-r--r--src/util/plugin/Plugin.ts9
-rw-r--r--src/util/plugin/PluginLoader.ts4
-rw-r--r--src/util/plugin/PluginManifest.ts1
3 files changed, 11 insertions, 3 deletions
diff --git a/src/util/plugin/Plugin.ts b/src/util/plugin/Plugin.ts
index 96e05843..1c86a006 100644
--- a/src/util/plugin/Plugin.ts
+++ b/src/util/plugin/Plugin.ts
@@ -6,7 +6,14 @@ type PluginEvents = {
 	loaded: () => void;
 };
 
-export class Plugin extends (EventEmitter as new () => TypedEventEmitter<PluginEvents>) {
+//this doesnt work, check later:
+ //(EventEmitter as new () => TypedEventEmitter<PluginEvents>) {
+export class Plugin extends EventEmitter {
+	private _untypedOn = this.on
+	private _untypedEmit = this.emit
+	public on = <K extends keyof PluginEvents>(event: K, listener: PluginEvents[K]): this => this._untypedOn(event, listener)
+	public emit = <K extends keyof PluginEvents>(event: K, ...args: Parameters<PluginEvents[K]>): boolean => this._untypedEmit(event, ...args)
+
 	async init() {
 		// insert default config into database?
 	}
diff --git a/src/util/plugin/PluginLoader.ts b/src/util/plugin/PluginLoader.ts
index b46ef269..e69cb499 100644
--- a/src/util/plugin/PluginLoader.ts
+++ b/src/util/plugin/PluginLoader.ts
@@ -2,7 +2,7 @@ import path from "path";
 import fs from "fs";
 import { Plugin, PluginManifest } from "./";
 
-const root = process.env.PLUGIN_LOCATION || "../plugins";
+const root = process.env.PLUGIN_LOCATION || "dist/plugins";
 
 let pluginsLoaded = false;
 export class PluginLoader {
@@ -24,7 +24,7 @@ export class PluginLoader {
 			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;
+			const module_ = require(path.join(modPath, manifest.index)) as Plugin;
 			try {
 				await module_.init();
 				module_.emit("loaded");
diff --git a/src/util/plugin/PluginManifest.ts b/src/util/plugin/PluginManifest.ts
index b171956b..01b2b084 100644
--- a/src/util/plugin/PluginManifest.ts
+++ b/src/util/plugin/PluginManifest.ts
@@ -6,4 +6,5 @@ export class PluginManifest {
     license: string;
 	version: string // semver
 	versionCode: number // integer
+    index: string;
 }
\ No newline at end of file