From 87d6a6778c6d502df511b639375fa219ac8713c6 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Sat, 13 Aug 2022 08:54:50 +0200 Subject: Update plugin loading, update example plugin, add ci task for testing if builds work --- .github/relase_body_template.md | 17 ----------------- .github/release_body_template.md | 17 +++++++++++++++++ .github/workflows/test_build.yml | 29 +++++++++++++++++++++++++++++ scripts/build.js | 10 +++++----- src/Server.ts | 7 ++----- src/plugins/example-plugin/ExamplePlugin.ts | 7 +++++++ src/plugins/example-plugin/plugin.json | 10 ++++++++++ src/util/index.ts | 2 ++ src/util/plugin/Plugin.ts | 9 ++++++++- src/util/plugin/PluginLoader.ts | 4 ++-- src/util/plugin/PluginManifest.ts | 1 + 11 files changed, 83 insertions(+), 30 deletions(-) delete mode 100644 .github/relase_body_template.md create mode 100644 .github/release_body_template.md create mode 100644 .github/workflows/test_build.yml create mode 100644 src/plugins/example-plugin/ExamplePlugin.ts create mode 100644 src/plugins/example-plugin/plugin.json diff --git a/.github/relase_body_template.md b/.github/relase_body_template.md deleted file mode 100644 index c410b0c2..00000000 --- a/.github/relase_body_template.md +++ /dev/null @@ -1,17 +0,0 @@ -## Notes - -## Additions - -- - -## Fixes - -- - -## Download - -- [Windows]() -- [MacOS]() -- [Linux]() - -After (extracting) and starting the server executable you can access your own Fosscord server on http://localhost:3001/ diff --git a/.github/release_body_template.md b/.github/release_body_template.md new file mode 100644 index 00000000..c410b0c2 --- /dev/null +++ b/.github/release_body_template.md @@ -0,0 +1,17 @@ +## Notes + +## Additions + +- + +## Fixes + +- + +## Download + +- [Windows]() +- [MacOS]() +- [Linux]() + +After (extracting) and starting the server executable you can access your own Fosscord server on http://localhost:3001/ diff --git a/.github/workflows/test_build.yml b/.github/workflows/test_build.yml new file mode 100644 index 00000000..dd8744e0 --- /dev/null +++ b/.github/workflows/test_build.yml @@ -0,0 +1,29 @@ +on: + workflow_dispatch: + push: + paths: + - "**" + +name: Test Build + +jobs: + insiders-build: + strategy: + matrix: + os: [windows, macos, ubuntu] + include: + - os: windows + - os: macos + - os: ubuntu + runs-on: ${{ matrix.os }}-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + env: + MONGOMS_VERSION: 4.4.3 + with: + node-version: 18 + - run: | + cd bundle + npm run setup + npm run build clean logerrors pretty-errors propagate-err diff --git a/scripts/build.js b/scripts/build.js index f618100c..7421aa4f 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -29,11 +29,11 @@ if (silent) console.error = console.log = function () {}; if (argv.includes("clean")) { console.log(`[${++i}/${steps}] Cleaning...`); - let d = "dist"; - if (fs.existsSync(d)) { - fs.rmSync(d, { recursive: true }); - if (verbose) console.log(`Deleted ${d}!`); - } + let d = "../" + "/dist"; + if (fs.existsSync(d)) { + fs.rmSync(d, { recursive: true }); + if (verbose) console.log(`Deleted ${d}!`); + } } console.log(`[${++i}/${steps}] Compiling src files ...`); diff --git a/src/Server.ts b/src/Server.ts index 83120412..e672bd0c 100644 --- a/src/Server.ts +++ b/src/Server.ts @@ -7,10 +7,7 @@ import * as Gateway from "@fosscord/gateway"; import { Config, getOrInitialiseDatabase } from "@fosscord/util"; import * as Sentry from "@sentry/node"; import * as Tracing from "@sentry/tracing"; -import express from "express"; -import http from "http"; -import { bold, green, yellow } from "picocolors"; -// import { PluginLoader } from "@fosscord/util"; +import { PluginLoader } from "@fosscord/util"; const app = express(); const server = http.createServer(); @@ -64,7 +61,7 @@ async function main() { } console.log(`[Server] ${green(`listening on port ${bold(port)}`)}`); - // PluginLoader.loadPlugins(); + PluginLoader.loadPlugins(); } main().catch(console.error); diff --git a/src/plugins/example-plugin/ExamplePlugin.ts b/src/plugins/example-plugin/ExamplePlugin.ts new file mode 100644 index 00000000..e6f70657 --- /dev/null +++ b/src/plugins/example-plugin/ExamplePlugin.ts @@ -0,0 +1,7 @@ +import { Plugin } from "@fosscord/util"; + +export default class TestPlugin extends Plugin { + onPluginLoaded(): void { + console.log("Hello from test plugin! IT WORKS!!!!!!!"); + } +} \ No newline at end of file diff --git a/src/plugins/example-plugin/plugin.json b/src/plugins/example-plugin/plugin.json new file mode 100644 index 00000000..2fcb7a00 --- /dev/null +++ b/src/plugins/example-plugin/plugin.json @@ -0,0 +1,10 @@ +{ + "id": "example-plugin", + "name": "Fosscord example plugin", + "authors": [ + "The Arcane Brony" + ], + "repository": "https://github.com/fosscord/fosscord-server", + "license": "", + "index": "ExamplePlugin.js" +} diff --git a/src/util/index.ts b/src/util/index.ts index b26ed278..0cf30a71 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -7,3 +7,5 @@ export * from "./interfaces/index"; export * from "./schemas"; export * from "./util/index"; export * from "./util/MFA"; +export * from "./schemas"; +export * from "./plugin"; \ No newline at end of file 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) { +//this doesnt work, check later: + //(EventEmitter as new () => TypedEventEmitter) { +export class Plugin extends EventEmitter { + private _untypedOn = this.on + private _untypedEmit = this.emit + public on = (event: K, listener: PluginEvents[K]): this => this._untypedOn(event, listener) + public emit = (event: K, ...args: Parameters): 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 -- cgit 1.4.1