Update plugin loading, update example plugin, add ci task for testing if builds work

This commit is contained in:
TheArcaneBrony
2022-08-13 08:54:50 +02:00
parent 2c40b1ebae
commit 87d6a6778c
10 changed files with 66 additions and 13 deletions
+29
View File
@@ -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
+5 -5
View File
@@ -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 ...`);
+2 -5
View File
@@ -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);
@@ -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!!!!!!!");
}
}
+10
View File
@@ -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"
}
+2
View File
@@ -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";
+8 -1
View File
@@ -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?
}
+2 -2
View File
@@ -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");
+1
View File
@@ -6,4 +6,5 @@ export class PluginManifest {
license: string;
version: string // semver
versionCode: number // integer
index: string;
}