Files
drb-server/src/modules/addonManager.mjs
Logan Cusano 066404dd10
Some checks failed
Update Wiki from JSDoc / update-wiki (pull_request) Has been cancelled
Lint JavaScript/Node.js / lint-js (pull_request) Failing after 11s
DRB Tests / drb_mocha_tests (pull_request) Has been cancelled
Updated dir structure to put the actual source code in the general /src dir
2024-08-17 18:44:18 -04:00

46 lines
1.4 KiB
JavaScript

import { DebugBuilder } from "../modules/debugger.mjs";
const log = new DebugBuilder("server", "addonManager");
import { fileURLToPath } from "url";
import fs from "fs";
import path from "path";
// Function to load addons from the addons directory
export const loadAddons = async (nodeIo) => {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const addonsDir = path.join(__dirname, "../addons");
// Read the directory containing addon modules
const addonDirectories = await fs.readdirSync(addonsDir, {
withFileTypes: true,
});
addonDirectories.forEach((addonDir) => {
if (addonDir.isDirectory()) {
const addonConfigPath = path.join(
addonsDir,
addonDir.name,
"config.json",
);
if (fs.existsSync(addonConfigPath)) {
const addonConfig = JSON.parse(
fs.readFileSync(addonConfigPath, "utf-8"),
);
if (addonConfig.enabled) {
const addonIndexPath = path.join(
addonsDir,
addonDir.name,
"index.js",
);
import(`file://${addonIndexPath}`).then((addonModule) => {
log.DEBUG("Loading addon: ", addonModule);
addonModule.initialize(nodeIo, addonConfig);
log.DEBUG(`Addon ${addonConfig.name} loaded.`);
});
}
}
}
});
};