- Added a config system to the addons
- Added options in the config for dynamic variables
- Updated example and code to use new config and options
This commit is contained in:
Logan Cusano
2024-03-10 04:50:16 -04:00
parent 7d4f48a446
commit bee95ed999
4 changed files with 37 additions and 25 deletions

View File

@@ -6,7 +6,7 @@ import path from 'path';
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
@@ -14,13 +14,18 @@ export const loadAddons = async (nodeIo) => {
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.`);
})
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 => {
console.log("Loading addon: ", addonModule);
addonModule.initialize(nodeIo, addonConfig);
console.log(`Addon ${addonConfig.name} loaded.`);
});
}
}
}
});
}