renderAllTemplates static method
Renders all .mustache files in a folder using context
Implementation
static void renderAllTemplates(
String sourcePath, String targetPath, Map<String, dynamic> context) {
final templateDir = Directory(sourcePath);
if (!templateDir.existsSync()) {
throw Exception("Template folder not found at $sourcePath");
}
print('🧩 Rendering templates from $sourcePath → $targetPath');
for (var entity in templateDir.listSync(recursive: true)) {
if (entity is File && entity.path.endsWith('.mustache')) {
final relativePath = p.relative(entity.path, from: sourcePath);
final targetFile =
File(p.join(targetPath, relativePath.replaceAll('.mustache', '')))
..parent.createSync(recursive: true);
try {
final template = Template(entity.readAsStringSync());
final rendered = template.renderString(context);
targetFile.writeAsStringSync(rendered);
print('📄 Created: $relativePath → ${p.basename(targetFile.path)}');
} catch (e) {
print('❌ Failed to render $relativePath: $e');
}
}
}
}