render method
Renders template using variables into destinationPath.
If overwriteExisting is false (default), throws DestinationConflictException
if any target destination file already exists.
Throws UnresolvedTokenException if any path or content token is unresolved.
Implementation
RenderResult render({
required Template template,
required Map<String, String> variables,
required String destinationPath,
bool overwriteExisting = false,
}) {
final destDir = Directory(destinationPath);
if (!destDir.existsSync()) {
destDir.createSync(recursive: true);
}
final createdFiles = <String>[];
final createdFolders = <String>{};
// 1. Render files/ directory tree if present
if (template.path != null) {
final filesSourceDir = Directory(p.join(template.path!, 'files'));
if (filesSourceDir.existsSync()) {
_renderDirectoryTree(
sourceDir: filesSourceDir,
rootSourcePath: filesSourceDir.path,
destinationRoot: destinationPath,
variables: variables,
overwriteExisting: overwriteExisting,
createdFiles: createdFiles,
createdFolders: createdFolders,
);
}
}
// 2. Render YAML-declared folders (from template.config.folders)
for (final folderConfig in template.config.folders) {
final resolvedRelativePath = TokenSubstitutor.substitute(
folderConfig.path,
variables,
);
final targetFolderPath = p.join(destinationPath, resolvedRelativePath);
final folderDir = Directory(targetFolderPath);
if (!folderDir.existsSync()) {
folderDir.createSync(recursive: true);
}
createdFolders.add(p.relative(targetFolderPath, from: destinationPath));
}
final sortedFolders = createdFolders.toList()..sort();
final sortedFiles = createdFiles..sort();
return RenderResult(
createdFiles: List.unmodifiable(sortedFiles),
createdFolders: List.unmodifiable(sortedFolders),
);
}