generateFeature method
Creates directories and generates all boilerplate files for the feature.
Implementation
Future<void> generateFeature(
Context context, {
bool overwrite = false,
}) async {
final featureName = context.nameLowerCase;
final basePath = '${context.projectRoot}/lib/features/$featureName';
final generateUseCase = context.generateUseCase;
final templateBasePath =
_templateBasePath ?? await _resolveTemplateBasePath();
// Create feature folders in a conventional clean-architecture layout.
final folders = [
'$basePath/data/models',
'$basePath/data/repositories',
'$basePath/data/datasources',
'$basePath/domain/entities',
'$basePath/domain/repositories',
if (generateUseCase) '$basePath/domain/usecases',
if (context.config.layer == PresentationLayer.bloc)
'$basePath/presentation/bloc',
if (context.config.layer == PresentationLayer.riverpod)
'$basePath/presentation/riverpod',
if (context.config.layer == PresentationLayer.getx)
'$basePath/presentation/getx',
if (context.config.layer != null) '$basePath/presentation/screen',
];
if (generateUseCase) {
folders.add('${context.projectRoot}/lib/features/shared/usecase');
}
// Create core folders
folders.add('${context.projectRoot}/lib/core/di');
for (var folder in folders) {
Directory(folder).createSync(recursive: true);
}
generateBoilerplate(
featureName: featureName,
basePath: basePath,
templateBasePath: templateBasePath,
context: context,
overwrite: overwrite,
);
}