renderFile method
Implementation
Future<void> renderFile({
required String sourcePath,
required String targetPath,
required Map<String, String> variables,
Map<String, bool>? conditions,
Map<String, List<Map<String, String>>>? lists,
}) async {
final sourceFile = File(sourcePath);
if (!sourceFile.existsSync()) {
throw Exception('Template file not found: $sourcePath');
}
var content = await sourceFile.readAsString();
content = renderContent(
content,
variables,
conditions: conditions,
lists: lists,
);
final targetFile = File(targetPath);
final targetParent = targetFile.parent;
if (!targetParent.existsSync()) {
targetParent.createSync(recursive: true);
}
await targetFile.writeAsString(content);
}