diff --git a/.github/relase_body_template.md b/.github/release_body_template.md similarity index 100% rename from .github/relase_body_template.md rename to .github/release_body_template.md diff --git a/.github/workflows/test_build.yml b/.github/workflows/test_build.yml new file mode 100644 index 000000000..dd8744e09 --- /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 f618100ca..7421aa4fb 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 831204126..e672bd0c5 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 000000000..e6f706574 --- /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 000000000..2fcb7a008 --- /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 b26ed2787..0cf30a71d 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 96e058436..1c86a0067 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 b46ef269a..e69cb4998 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 b171956b4..01b2b0844 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