getOrphanedFlavors static method

Set<String> getOrphanedFlavors(
  1. List<String> currentFlavors
)

Implementation

static Set<String> getOrphanedFlavors(List<String> currentFlavors) {
  final orphans = <String>{};

  // 1. Check lib/main/
  final mainDir = Directory(p.join(ConfigService.root, 'lib/main'));
  if (mainDir.existsSync()) {
    for (final entity in mainDir.listSync()) {
      if (entity is File) {
        final name = p.basename(entity.path);
        final match = RegExp(r'^main_(.*)\.dart$').firstMatch(name);
        if (match != null) {
          final flavor = match.group(1)!;
          if (!currentFlavors.contains(flavor)) {
            orphans.add(flavor);
          }
        }
      }
    }
  }

  // 2. Check ios/Flutter/
  final iosDir = Directory(p.join(ConfigService.root, 'ios/Flutter'));
  if (iosDir.existsSync()) {
    for (final entity in iosDir.listSync()) {
      if (entity is File) {
        final name = p.basename(entity.path);
        final match = RegExp(r'^(.*)\.xcconfig$').firstMatch(name);
        if (match != null) {
          final flavor = match.group(1)!;
          // Ignore standard files
          if (flavor == 'Generated' ||
              flavor == 'Release' ||
              flavor == 'Debug') {
            continue;
          }

          if (!currentFlavors.contains(flavor)) {
            orphans.add(flavor);
          }
        }
      }
    }
  }

  return orphans;
}