run method

  1. @override
Future<void> run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
Future<void> run() async {
  final projectDir = argResults?['project-dir'] as String;

  // Check if it's a Flutter project
  final pubspecFile = File(path.join(projectDir, 'pubspec.yaml'));
  if (!pubspecFile.existsSync()) {
    printError('Cannot find pubspec.yaml. Are you in a Flutter project?');
    exit(1);
  }

  try {
    final pubspecContent = pubspecFile.readAsStringSync();
    final pubspec = loadYaml(pubspecContent);

    if (pubspec['dependencies'] == null ||
        pubspec['dependencies']['flutter'] == null) {
      printError('This does not appear to be a Flutter project.');
      exit(1);
    }

    print('🚀 Initializing BlocY in ${path.absolute(projectDir)}');

    // Add dependencies
    await addDependencies(projectDir);

    // Create folder structure
    createFolderStructure(projectDir);

    // Create basic files
    createBaseFiles(projectDir);

    printSuccess('✅ BlocY initialization complete!');

    // Generate home feature automatically
    print('\n🏠 Creating home feature...');
    updateTestFiles(projectDir);
    await createHomeFeature(projectDir);

    print('\nRun "flutter pub get" to install the new dependencies.');
  } catch (e) {
    printError('Failed to initialize BlocY: $e');
    exit(1);
  }
}