mirror of
https://github.com/spacebarchat/server.git
synced 2026-04-10 03:35:41 +00:00
feat(plugins): loader
This commit is contained in:
committed by
TheArcaneBrony
parent
e3b59bca98
commit
fc0465dee1
5
src/util/plugin/Plugin.ts
Normal file
5
src/util/plugin/Plugin.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export class Plugin {
|
||||
onPluginLoaded() {
|
||||
console.log('no onpluginloaded!')
|
||||
}
|
||||
}
|
||||
32
src/util/plugin/PluginLoader.ts
Normal file
32
src/util/plugin/PluginLoader.ts
Normal file
@@ -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 =
|
||||
}
|
||||
}
|
||||
9
src/util/plugin/PluginManifest.ts
Normal file
9
src/util/plugin/PluginManifest.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export class PluginManifest {
|
||||
id: string;
|
||||
name: string;
|
||||
authors: string[];
|
||||
repository: string;
|
||||
license: string;
|
||||
version: string // semver
|
||||
versionCode: number // integer
|
||||
}
|
||||
3
src/util/plugin/index.ts
Normal file
3
src/util/plugin/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./Plugin";
|
||||
export * from "./PluginLoader";
|
||||
export * from "./PluginManifest";
|
||||
Reference in New Issue
Block a user