2024-10-01 12:57:53 +00:00
|
|
|
const fs = require('fs');
|
2024-10-19 12:20:21 +00:00
|
|
|
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-15 12:50:14 +00:00
|
|
|
const { getIo } = require('../io/socket');
|
2024-10-19 12:20:21 +00:00
|
|
|
const { datagenTask } = require('./datagen');
|
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, '../')
|
|
|
|
|
|
|
|
let pluginsInfo = [];
|
|
|
|
let plugins = {};
|
2024-10-15 12:50:14 +00:00
|
|
|
let internalSocket = {};
|
2024-10-19 12:20:21 +00:00
|
|
|
let datagenRegistry = {};
|
2024-10-01 12:57:53 +00:00
|
|
|
|
|
|
|
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-19 12:20:21 +00:00
|
|
|
datagenRegistry[k] = {modelNames: []};
|
|
|
|
let pluginApi = new BackendApi(plugins[k].info, router, internalSocket, datagenRegistry[k]);
|
2024-10-14 13:50:47 +00:00
|
|
|
plugins[k].payload.Main(pluginApi);
|
|
|
|
});
|
|
|
|
|
2024-10-19 12:20:21 +00:00
|
|
|
datagenTask(datagenRegistry);
|
|
|
|
|
2024-10-15 12:50:14 +00:00
|
|
|
console.log(internalSocket);
|
|
|
|
getIo().on('connect', (socket) => {
|
|
|
|
Object.keys(internalSocket).forEach(k => {
|
|
|
|
socket.on(k, internalSocket[k]);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
2024-10-14 13:50:47 +00:00
|
|
|
return {
|
|
|
|
router
|
|
|
|
}
|
2024-10-01 12:57:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
init
|
|
|
|
}
|