const fs = require('fs');
const path = require('path');
const glob = require('glob');
/**
* Boots scripts from files defined in a configuration file.
* @param {string} configFilePath Path to the configuration file (JSON).
*/
async function bootstrapScripts(configFilePath) {
try {
const config = JSON.parse(fs.readFileSync(configFilePath, 'utf8'));
if (!config || !config.scripts) {
console.warn('Configuration file is invalid or missing "scripts" section.');
return;
}
const scriptFiles = config.scripts.map(script => script.path); // Extract file paths
for (const scriptFile of scriptFiles) {
try {
// Execute each script file
const scriptPath = path.resolve(scriptFile);
if (fs.existsSync(scriptPath)) {
require(scriptPath); // dynamically require and execute
console.log(`Executed script: ${scriptPath}`);
} else {
console.warn(`Script file not found: ${scriptFile}`);
}
} catch (error) {
console.error(`Error executing script ${scriptFile}:`, error);
}
}
} catch (error) {
console.error('Error reading or parsing configuration file:', error);
}
}
// Example usage:
// bootstrapScripts('config.json');
module.exports = bootstrapScripts;
Add your comment