ensureFileExists static method
void
ensureFileExists(
{ - required String templatePath,
- required String targetPath,
})
Implementation
static void ensureFileExists({required String templatePath, required String targetPath}) {
final targetFile = File(targetPath);
final targetDir = targetFile.parent;
// create dir if missing
if (!targetDir.existsSync()) {
targetDir.createSync(recursive: true);
}
if (!targetFile.existsSync()) {
final templateFile = File(templatePath);
if (templateFile.existsSync()) {
targetFile.writeAsStringSync(templateFile.readAsStringSync());
print('✅ File copied from $templatePath to $targetPath');
} else {
print('❌ Template file missing: $templatePath');
}
} else {
print('✅ File already exists at $targetPath');
}
}