renderTemplate method
void
renderTemplate(})
Reads a .mustache template, injects context values, and writes to outPath
only if it does not already exist (or when overwrite is true).
This is intentionally synchronous to keep file creation predictable. Throws a descriptive StateError when the template file cannot be found, so a corrupt or incomplete install produces a clear message.
Implementation
void renderTemplate(
String templatePath,
String outPath,
Map<String, dynamic> context, {
required bool overwrite,
}) {
final outFile = File(outPath);
if (!overwrite && outFile.existsSync()) {
return;
}
final String templateString;
try {
templateString = File(templatePath).readAsStringSync();
} on FileSystemException catch (e) {
throw StateError(
'Template not found at "$templatePath". '
'Is the package correctly installed?\n $e',
);
}
final template = Template(templateString);
final result = template.renderString(context);
outFile.writeAsStringSync(result);
}