setupCocoaPods method

  1. @override
Future<void> setupCocoaPods(
  1. String projectName,
  2. List<PlatformType> platforms
)
override

Implementation

@override
Future<void> setupCocoaPods(String projectName, List<PlatformType> platforms) async {
  final bool hasIOS = platforms.contains(PlatformType.mobile) &&
                      Directory('$projectName/ios').existsSync();
  final bool hasMacOS = platforms.contains(PlatformType.desktop) &&
                        Directory('$projectName/macos').existsSync();

  if (!hasIOS && !hasMacOS) {
    return;
  }

  try {
    final podCheck = await Process.run('which', ['pod']);
    if (podCheck.exitCode != 0) {
      return; // CocoaPods not installed, skip silently
    }

    // Setup iOS CocoaPods
    if (hasIOS) {
      final iosDir = Directory('$projectName/ios');
      if (iosDir.existsSync()) {
        final podsDir = Directory('$projectName/ios/Pods');
        final podfileLock = File('$projectName/ios/Podfile.lock');

        if (podsDir.existsSync()) {
          await podsDir.delete(recursive: true);
        }
        if (podfileLock.existsSync()) {
          await podfileLock.delete();
        }

        await Process.run('pod', ['repo', 'update'], workingDirectory: '$projectName/ios');
        await Process.run('pod', ['install', '--repo-update'], workingDirectory: '$projectName/ios');
      }
    }

    // Setup macOS CocoaPods
    if (hasMacOS) {
      final macosDir = Directory('$projectName/macos');
      if (macosDir.existsSync()) {
        final podsDir = Directory('$projectName/macos/Pods');
        final podfileLock = File('$projectName/macos/Podfile.lock');

        if (podsDir.existsSync()) {
          await podsDir.delete(recursive: true);
        }
        if (podfileLock.existsSync()) {
          await podfileLock.delete();
        }

        await Process.run('pod', ['repo', 'update'], workingDirectory: '$projectName/macos');
        await Process.run('pod', ['install', '--repo-update'], workingDirectory: '$projectName/macos');
      }
    }
  } catch (e) {
    // Silently handle - user can run pod install manually if needed
  }
}