execute method
Implementation
Future<void> execute() async {
final snakeName = StringUtils.toSnakeCase(featureName);
final pascalName = StringUtils.toPascalCase(featureName);
final camelName = StringUtils.toCamelCase(featureName);
// Check if running from project root
final currentDir = Directory.current.path;
final melosFile = File('$currentDir/melos.yaml');
final packagesDir = Directory('$currentDir/packages');
if (!melosFile.existsSync() || !packagesDir.existsSync()) {
Logger.error(
'❌ Please run this command from the project root directory!',
);
Logger.error(
' (The directory containing melos.yaml and packages/ folder)',
);
print('');
print('Current directory: ${_cyan}$currentDir$_reset');
print('Expected files: ${_cyan}melos.yaml, packages/$_reset');
exit(1);
}
Logger.header('Removing Feature: $snakeName');
// Check if feature exists
final featurePath = '$currentDir/packages/features_$snakeName';
final featureDir = Directory(featurePath);
if (!featureDir.existsSync()) {
Logger.error('Feature "features_$snakeName" does not exist!');
Logger.warning('Available features:');
final packagesDirectory = Directory('$currentDir/packages');
await for (var entity in packagesDirectory.list()) {
if (entity is Directory && entity.path.contains('features_')) {
final name = entity.path.split('/').last;
Logger.warning(' • $name');
}
}
exit(1);
}
// Ask for confirmation
print('');
print('${_red}⚠️ WARNING: This will permanently delete:$_reset');
print(' • Feature directory: features_$snakeName');
print(' • Route from app_routes.dart');
print(' • GoRoute from app_router.dart');
print(' • Dependency from app/pubspec.yaml');
print('');
stdout.write('Are you sure you want to continue? (yes/no): ');
final confirmation = stdin.readLineSync()?.toLowerCase().trim();
if (confirmation != 'yes' && confirmation != 'y') {
Logger.warning('Operation cancelled.');
exit(0);
}
print('');
// Remove from app/pubspec.yaml
Logger.step('Removing from app/pubspec.yaml...');
_removeFromAppPubspec(snakeName);
Logger.success('Removed from app/pubspec.yaml');
// Remove routes from app_routes.dart
Logger.step('Removing routes from app_routes.dart...');
_removeRoutesFromAppRoutes(snakeName, camelName, pascalName);
Logger.success('Removed routes from app_routes.dart');
// Remove from app_router.dart
Logger.step('Removing from app_router.dart...');
_removeFromAppRouter(snakeName, pascalName, camelName);
Logger.success('Removed from app_router.dart');
// Delete feature directory
Logger.step('Deleting feature directory...');
try {
featureDir.deleteSync(recursive: true);
Logger.success('Feature directory deleted');
} catch (e) {
Logger.error('Failed to delete feature directory: $e');
exit(1);
}
Logger.header('Feature Removed Successfully! 🗑️');
print('''
${_green}✨ What was removed:$_reset
• Feature directory: packages/features_$snakeName
• Dependency from app/pubspec.yaml
• Route constants from app_routes.dart
• Navigation helper from app_routes.dart
• GoRoute registration from app_router.dart
${_yellow}⚠️ Don't forget to:$_reset
1. Remove dependency registrations from app/lib/injection_container.dart
2. Run: ${_cyan}flutter pub get${_reset} in the app package
''');
}