@gambito-corp/mbs-library
Version:
Librería de componentes React reutilizables - Sistema de diseño modular y escalable
21 lines (15 loc) • 631 B
JavaScript
import fs from 'fs-extra';
import path from 'path';
export async function generateFromTemplate(templateName, data) {
const templatePath = path.join(__dirname, '..', 'stubs', templateName);
if (!await fs.pathExists(templatePath)) {
throw new Error(`Plantilla no encontrada: ${templateName}`);
}
let template = await fs.readFile(templatePath, 'utf8');
// Reemplazar variables en la plantilla
for (const [key, value] of Object.entries(data)) {
const regex = new RegExp(`{{${key}}}`, 'g');
template = template.replace(regex, value);
}
return template;
}