initializeProject function

void initializeProject()

Implementation

void initializeProject() {
  stdout.write('Enter project name: ');
  final projectName = stdin.readLineSync()?.trim();
  if (projectName == null || projectName.isEmpty) {
    print('Project name is required.');
    return;
  }

  final pascalCaseAppName = projectName.pascalCase;
  final snakeCaseAppName = projectName.snakeCase;

  stdout.write('Enter initial feature name (optional): ');
  final featureName = stdin.readLineSync()?.trim().snakeCase;

  // Create Flutter project (override)
  print('Initializing Flutter project...');
  Process.runSync('flutter', ['create', '.'], workingDirectory: Directory.current.path);

  // Add dependencies
  addDependencies(Constants.dependencies);
  addDevDependencies(Constants.devDependencies);

  // Create directories
  print('Creating project structure...');
  createDirectories([
    'assets/audios',
    'assets/fonts',
    'assets/icons',
    'assets/images',
    'assets/translations',
    'lib/config/routes',
    'lib/config/theme',
    'lib/src/core/network',
    'lib/src/core/resources',
    'lib/src/core/usecases',
    'lib/src/core/utils',
    'lib/src/features/${featureName ?? ''}/data/data_sources',
    'lib/src/features/${featureName ?? ''}/data/models',
    'lib/src/features/${featureName ?? ''}/data/repository',
    'lib/src/features/${featureName ?? ''}/domain/entities',
    'lib/src/features/${featureName ?? ''}/domain/repository',
    'lib/src/features/${featureName ?? ''}/domain/usecases',
    'lib/src/features/${featureName ?? ''}/presentation/bloc',
    'lib/src/features/${featureName ?? ''}/presentation/pages',
    'lib/src/features/${featureName ?? ''}/presentation/widgets',
  ]);

  updatePubspec();

  // Create initial files
  print('Generating boilerplate code...');
  createFile('lib/main.dart', generateMainDart(snakeCaseAppName));
  createFile('test/widget_test.dart', generateTestDart());
  createFile('lib/src/$snakeCaseAppName.dart', generateAppDart(pascalCaseAppName));
  createFile('lib/config/config.dart', generateConfigDart(pascalCaseAppName));
  createFile('lib/config/routes/app_routes.dart', generateAppRoutesDart());
  createFile('lib/config/routes/app_pages.dart', generateAppPagesDart());
  createFile('lib/src/core/resources/data_state.dart', generateDataStateDart());

  print('Project initialization complete!');
}