2024-10-01 12:57:53 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path')
|
2024-10-05 12:31:09 +00:00
|
|
|
const BackendApi = require('./api').BackendApi
|
2024-10-14 13:50:47 +00:00
|
|
|
const express = require('express');
|
2024-10-14 17:25:46 +00:00
|
|
|
const router = express.Router({
|
|
|
|
mergeParams: true
|
|
|
|
});
|
2024-10-01 12:57:53 +00:00
|
|
|
|
|
|
|
const basePath = path.resolve(__dirname, '../')
|
|
|
|
console.log(basePath)
|
|
|
|
|
|
|
|
let pluginsInfo = [];
|
|
|
|
let plugins = {};
|
|
|
|
|
|
|
|
function init(){
|
|
|
|
console.log("Initializing plugins");
|
|
|
|
const pluginFolders = fs.readdirSync(path.resolve(basePath + '/plugins'));
|
|
|
|
pluginFolders.forEach(pluginFolder => {
|
|
|
|
pluginsInfo.push(JSON.parse(fs.readFileSync(
|
|
|
|
path.resolve(basePath, 'plugins', pluginFolder, "plugin.json")
|
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log("Launching using the following plugins:");
|
|
|
|
pluginsInfo.forEach(pluginInfo => {
|
|
|
|
console.log(`\t- ${pluginInfo.name}`);
|
2024-10-05 17:27:28 +00:00
|
|
|
plugins[pluginInfo.package] = {info: pluginInfo, payload: require(`${basePath}/plugins/${pluginInfo.package}/${pluginInfo.backend.entrypoint}`)};
|
2024-10-01 12:57:53 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Execute main
|
|
|
|
Object.keys(plugins).forEach(k => {
|
2024-10-14 17:25:46 +00:00
|
|
|
let pluginApi = new BackendApi(plugins[k].info, router);
|
2024-10-14 13:50:47 +00:00
|
|
|
plugins[k].payload.Main(pluginApi);
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
router
|
|
|
|
}
|
2024-10-01 12:57:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
init
|
|
|
|
}
|