*Refactor how core plugins are loaded

This commit is contained in:
Derrick Hammer 2023-01-07 23:02:13 -05:00
parent 5c85ad2962
commit ce23f0a7b8
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 11 additions and 6 deletions

View File

@ -8,9 +8,6 @@ import path from "path";
import type { Logger } from "pino"; import type { Logger } from "pino";
import { getHDKey, getSeed } from "../lib/seed.js"; import { getHDKey, getSeed } from "../lib/seed.js";
import pluginRpc from "../plugins/rpc";
import pluginCore from "../plugins/core";
import pluginDht from "../plugins/dht";
import type Config from "@lumeweb/cfg"; import type Config from "@lumeweb/cfg";
import EventEmitter2 from "eventemitter2"; import EventEmitter2 from "eventemitter2";
import log from "../log.js"; import log from "../log.js";
@ -21,6 +18,7 @@ import {
} from "./swarm.js"; } from "./swarm.js";
import { get as getSSl, SSLManager } from "./ssl.js"; import { get as getSSl, SSLManager } from "./ssl.js";
import type { HDKey } from "micro-ed25519-hdkey"; import type { HDKey } from "micro-ed25519-hdkey";
import corePlugins from "../plugins";
let pluginAPIManager: PluginAPIManager; let pluginAPIManager: PluginAPIManager;
let pluginAPI: PluginAPI; let pluginAPI: PluginAPI;
@ -228,9 +226,9 @@ export function getPluginAPIManager(): PluginAPIManager {
export async function loadPlugins() { export async function loadPlugins() {
const apiManager = getPluginAPIManager(); const apiManager = getPluginAPIManager();
apiManager.loadPluginInstance(pluginCore); for (const plugin of corePlugins) {
apiManager.loadPluginInstance(pluginRpc); await apiManager.loadPluginInstance(plugin);
apiManager.loadPluginInstance(pluginDht); }
for (const plugin of [...new Set(config.array("plugins", []))] as []) { for (const plugin of [...new Set(config.array("plugins", []))] as []) {
await apiManager.loadPlugin(plugin); await apiManager.loadPlugin(plugin);

7
src/plugins/index.ts Normal file
View File

@ -0,0 +1,7 @@
import core from "./core";
import rpc from "./rpc";
import dht from "./dht";
const corePlugins = [core, dht, rpc];
export default corePlugins;