renderFile method

Future<void> renderFile({
  1. required String sourcePath,
  2. required String targetPath,
  3. required Map<String, String> variables,
  4. Map<String, bool>? conditions,
  5. Map<String, List<Map<String, String>>>? lists,
})

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);
}