updateDevelopmentTeam method

void updateDevelopmentTeam({
  1. required String teamId,
})

Rewrites every DEVELOPMENT_TEAM entry in the iOS project file.

Implementation

void updateDevelopmentTeam({required String teamId}) {
  final file = pbxprojFile;

  if (!file.existsSync()) {
    throw BuildException(
      'project.pbxproj not found at "${file.path}"',
      fix: 'Ensure the iOS project directory is intact.',
    );
  }

  try {
    final contents = file.readAsStringSync();
    final pattern = RegExp(r'DEVELOPMENT_TEAM = [^;]+;');

    if (!pattern.hasMatch(contents)) {
      Logger.warning(
          'DEVELOPMENT_TEAM key not found in project.pbxproj; leaving signing untouched.');
      return;
    }

    final updated = contents.replaceAll(
      pattern,
      'DEVELOPMENT_TEAM = $teamId;',
    );

    file.writeAsStringSync(updated);
    Logger.info('Set iOS DEVELOPMENT_TEAM to $teamId');
  } catch (e, s) {
    throw BuildException(
      'Failed to update iOS DEVELOPMENT_TEAM in project.pbxproj',
      fix: 'Check file permissions for "${file.path}".',
      originalStackTrace: s,
    );
  }
}