You've already forked fm-dx-webserver
mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-02-26 22:13:53 +01:00
hotfix for plugins (missing files)
This commit is contained in:
67
server/plugins.js
Normal file
67
server/plugins.js
Normal file
@@ -0,0 +1,67 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { serverConfig } = require('./server_config');
|
||||
|
||||
// Function to read all .js files in a directory
|
||||
function readJSFiles(dir) {
|
||||
const files = fs.readdirSync(dir);
|
||||
return files.filter(file => file.endsWith('.js'));
|
||||
}
|
||||
|
||||
// Function to parse plugin config from a file
|
||||
function parsePluginConfig(filePath) {
|
||||
const fileContent = fs.readFileSync(filePath, 'utf8');
|
||||
const pluginConfig = {};
|
||||
|
||||
// Assuming pluginConfig is a JavaScript object defined in each .js file
|
||||
try {
|
||||
const pluginExports = require(filePath);
|
||||
Object.assign(pluginConfig, pluginExports.pluginConfig);
|
||||
|
||||
// Check if pluginConfig has frontEndPath defined
|
||||
if (pluginConfig.frontEndPath) {
|
||||
const sourcePath = path.join(path.dirname(filePath), pluginConfig.frontEndPath);
|
||||
const destinationDir = path.join(path.dirname(filePath), '../web/js/plugins', pluginConfig.frontEndPath, '..');
|
||||
|
||||
// Check if the destination directory exists, if not, create it
|
||||
if (!fs.existsSync(destinationDir)) {
|
||||
fs.mkdirSync(destinationDir, { recursive: true }); // Create directory recursively
|
||||
}
|
||||
|
||||
// Copy the file to the destination directory
|
||||
const destinationFile = path.join(destinationDir, path.basename(sourcePath));
|
||||
fs.copyFileSync(sourcePath, destinationFile);
|
||||
console.log(`File copied from ${sourcePath} to ${destinationFile}`);
|
||||
} else {
|
||||
console.error(`Error: frontEndPath is not defined in ${filePath}`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(`Error parsing plugin config from ${filePath}: ${err}`);
|
||||
}
|
||||
|
||||
return pluginConfig;
|
||||
}
|
||||
|
||||
// Main function to collect plugin configs from all .js files in the 'plugins' directory
|
||||
function collectPluginConfigs() {
|
||||
const pluginsDir = path.join(__dirname, '../plugins');
|
||||
const jsFiles = readJSFiles(pluginsDir);
|
||||
|
||||
const pluginConfigs = [];
|
||||
jsFiles.forEach(file => {
|
||||
const filePath = path.join(pluginsDir, file);
|
||||
const config = parsePluginConfig(filePath);
|
||||
if (Object.keys(config).length > 0) {
|
||||
pluginConfigs.push(config);
|
||||
}
|
||||
});
|
||||
|
||||
return pluginConfigs;
|
||||
}
|
||||
|
||||
// Usage example
|
||||
const allPluginConfigs = collectPluginConfigs();
|
||||
|
||||
module.exports = {
|
||||
allPluginConfigs
|
||||
}
|
||||
Reference in New Issue
Block a user