renderFeature static method
Renders a new feature inside an existing project
Implementation
static void renderFeature(
String featureName,
String featurePath,
Map<String, dynamic> context,
) {
final templateDir = Directory(
p.join('lib', 'templates', 'project', 'lib', 'features', featureName));
if (!templateDir.existsSync()) {
throw Exception("Feature templates not found at $templateDir");
}
print('🧩 Generating feature "$featureName"...');
for (var entity in templateDir.listSync(recursive: true)) {
if (entity is File && entity.path.endsWith('.mustache')) {
final relativePath = p.relative(entity.path, from: templateDir.path);
final targetPath =
p.join(featurePath, relativePath.replaceAll('.mustache', ''));
final targetFile = File(targetPath)..parent.createSync(recursive: true);
try {
final templateContent = entity.readAsStringSync();
final template = Template(templateContent);
final rendered = template.renderString(context);
targetFile.writeAsStringSync(rendered);
} catch (e) {
print('❌ Failed to render $relativePath: $e');
}
}
}
print('✅ Feature "$featureName" generated successfully');
}