run method
Runs this command.
The return value is wrapped in a Future if necessary and returned by
CommandRunner.runCommand.
Implementation
@override
void run() async {
if (argResults?.rest.isEmpty ?? true) {
stdout.writeln('Usage: fsa generate dumb <path/to/component_name>');
return;
}
final fullPath = argResults!.rest.first;
final parts = fullPath.split('/');
final name = parts.last;
final nested = parts.sublist(0, parts.length - 1).join('/');
final pascal = _toPascalCase(name);
final snake = _toSnakeCase(name);
final targetFile = File(p.join(presentationPath, nested, 'widgets', '$snake.dart'));
if (targetFile.existsSync()) {
stdout.writeln('❌ Dumb component already exists.');
return;
}
stdout.writeln('🎨 Generating dumb component "$pascal"...');
await _createFile(targetFile.path, '''
import 'package:flutter/material.dart';
class ${pascal}Widget extends StatelessWidget {
const ${pascal}Widget({super.key});
@override
Widget build(BuildContext context) {
return const Center(
child: Text('$pascal Dumb Component'),
);
}
}
''');
stdout.writeln('✅ Dumb component "$pascal" created at ${p.relative(targetFile.path)}');
}