- Added a module to load addons - Added an example module that just extends the socketIO connection to add an console log
27 lines
902 B
JavaScript
27 lines
902 B
JavaScript
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 addonPath = path.join(addonsDir, addonDir.name, 'index.js');
|
|
|
|
import(`file://${addonPath}`).then(addon => {
|
|
console.log("Loading addon: ", addon);
|
|
addon.initialize(nodeIo);
|
|
console.log(`Addon ${addonDir.name} loaded.`);
|
|
})
|
|
}
|
|
});
|
|
}
|