/**
* Loads resources from text files for development with a dry-run mode.
*
* @param {string[]} filePaths An array of file paths to load.
* @param {boolean} dryRun Whether to only log the loading process without actually loading the resources. Defaults to true.
*/
async function loadTextFiles(filePaths, dryRun = true) {
for (const filePath of filePaths) {
try {
// Check if the file exists
if (!fs.existsSync(filePath)) {
console.warn(`File not found: ${filePath}`);
continue; // Skip to the next file
}
//Read the file content
const fileContent = fs.readFileSync(filePath, 'utf8');
if (dryRun) {
console.log(`[DRY-RUN] Loading: ${filePath}`);
console.log(`Content Preview: ${fileContent.substring(0, 100)}...`); //Show first 100 characters
} else {
// Actual loading logic (replace with your resource loading)
console.log(`Loading: ${filePath}`);
//Implement your resource loading here, e.g., parse JSON, etc.
//return await parseFileContent(fileContent); //Example, uncomment if needed
}
} catch (error) {
console.error(`Error loading ${filePath}: ${error}`);
}
}
}
// Import the 'fs' module (Node.js file system)
const fs = require('fs');
//Example Usage:
// const filesToLoad = ['data/config.txt', 'data/messages.txt'];
// loadTextFiles(filesToLoad);
Add your comment