initializeRouter function

Future<void> initializeRouter(
  1. String projectPath
)

Implementation

Future<void> initializeRouter(String projectPath) async {
  final flutterCmd = Platform.isWindows ? 'flutter.bat' : 'flutter';
  print('📦 Adding go_router dependency...');
  await Process.run(flutterCmd, ['pub', 'add', 'go_router'],
      workingDirectory: projectPath, runInShell: true);

  final projectName = getProjectName(projectPath);
  final content = getAppRouterTemplate(projectName);
  final routerDir = p.join(projectPath, 'lib', 'routes');
  final routerPath = p.join(routerDir, 'app_router.dart');

  safeCreateDir(routerDir);
  safeWriteFile(routerPath, content, projectPath: projectPath);

  // Migrate app.dart to use GoRouter
  await migrateAppToRouter(projectPath);

  print('✅ GoRouter initialized at lib/routes/app_router.dart');
}