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 page <page_name> [--type=<smart|simple|static>]');
return;
}
final name = argResults!.rest.first;
final type = argResults!['type'] as String;
final pascal = _toPascalCase(name);
final snake = _toSnakeCase(name);
final targetDir = Directory(p.join(presentationPath, snake));
if (targetDir.existsSync()) {
stdout.writeln('❌ Page directory already exists.');
return;
}
stdout.writeln('🚀 Generating $type page "$pascal"...');
final prefix = _getRelativePrefix(targetDir.path);
if (type == 'static') {
await _createFile(p.join(targetDir.path, 'view.dart'), _staticViewTemplate(pascal, prefix));
} else if (type == 'simple') {
await _createFile(p.join(targetDir.path, 'ui_state.dart'), _simpleUIStateTemplate(pascal));
await _createFile(p.join(targetDir.path, 'ui_state_notifier.dart'), _simpleNotifierTemplate(pascal));
await _createFile(p.join(targetDir.path, 'view.dart'), _simpleViewTemplate(pascal, prefix));
} else {
// Default: Smart
await _createFile(p.join(targetDir.path, 'ui_state.dart'), _uiStateTemplate(pascal));
await _createFile(p.join(targetDir.path, 'ui_state_notifier.dart'), _notifierTemplate(pascal));
await _createFile(p.join(targetDir.path, 'view.dart'), _viewTemplate(pascal, prefix, true));
}
stdout.writeln('✅ Page "$pascal" created.');
if (type != 'static') {
stdout.writeln('👉 Run: fvm flutter pub run build_runner build');
}
}