updateFastlaneFiles function
Updates Fastlane configuration files with client-specific details.
This function reads a specified Fastlane file (e.g., Fastfile),
and replaces placeholders for bundle ID, app version, and app version code
with the provided values. This ensures that Fastlane builds and uploads
are correctly configured for the specific client.
fastlanePath The path to the Fastlane file to be updated.
bundleId The application's bundle ID (package name).
appVersion The application's version string (e.g., "1.0.0").
appVersionCode An optional build number or version code for the application.
Throws a FileSystemException if the Fastlane file is not found or cannot be written.
Implementation
Future<void> updateFastlaneFiles({
required String fastlanePath,
required String bundleId,
required String appVersion,
String? appVersionCode,
}) async {
// Function to replace variables in Fastlane files
Future<void> updateFile(
String filePath,
Map<String, String> replacements,
) async {
final file = File(filePath);
if (!file.existsSync()) {
logger.e('❌ Fastlane file not found: $filePath');
return;
}
String content = file.readAsStringSync();
replacements.forEach((key, value) {
content = content.replaceAll(RegExp(key), value);
});
file.writeAsStringSync(content);
logger.i('✅ Updated $filePath');
}
// Define replacement mappings
final Map<String, String> replacements = {
r'bundleId = ".*?"': 'bundleId = "$bundleId"',
r'app_version = ".*?"': 'app_version = "$appVersion"',
r'app_version_code = ".*?"': 'app_version_code = "$appVersionCode"',
};
// Update Fastlane file
await updateFile(fastlanePath, replacements);
}