In the script below I need to search in multiple files, and find a string, and replace with another.
It's basically version numbers (which need incrementing). Every time I find the old version number, and replace with a new version number.
The script is working well, but maybe has a cleaner way to search the old version number, because now I enter all the values manually.
It needs to be bulletproof, because if the file string version numbers changed with another third party app or script, the new version numbers must be the next number when running the script (currently, the version number check is done manually).
Can you give me any clues to improve the script?
oldVersion='1\.1\.10'
oldBuildNum='14'
oldVersionCode='22'
oldCurrentProjectVersion='20'
newVersion='1\.1\.11'
newBuildNum='15'
newVersionCode='23'
newCurrentProjectVersion='21'
canonical=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)/")
xcodePath="${canonical}ios/Runner.xcodeproj/project.pbxproj"
sed -i -e "s/MARKETING_VERSION = ${oldVersion}/MARKETING_VERSION = ${newVersion}/g" "$xcodePath"
sed -i -e "s/FLUTTER_BUILD_NAME = ${oldVersion}/FLUTTER_BUILD_NAME = ${newVersion}/g" "$xcodePath"
sed -i -e "s/FLUTTER_BUILD_NUMBER = ${oldBuildNum}/FLUTTER_BUILD_NUMBER = ${newBuildNum}/g" "$xcodePath"
sed -i -e "s/CURRENT_PROJECT_VERSION = ${oldCurrentProjectVersion}/CURRENT_PROJECT_VERSION = ${newCurrentProjectVersion}/g" "$xcodePath"
pubspec="${canonical}pubspec.yaml"
# The version string format here is: version: 1.1.10+22
sed -i -e "s/version: ${oldVersion}+${oldVersionCode}/version: ${newVersion}+${newVersionCode}/g" "$pubspec"
android="${canonical}android/local.properties"
sed -i -e "s/flutter\.versionName=${oldVersion}/flutter\.versionName=${newVersion}/g" $android
sed -i -e "s/flutter\.versionCode=${oldVersionCode}/flutter\.versionCode=${newVersionCode}/g" $android