Last active
June 28, 2022 09:27
-
-
Save jeremycastelli/8df74cd06b69a1c0c51f44f9e76de6c8 to your computer and use it in GitHub Desktop.
capacitor update Android and iOS app version script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const replace = require('replace'); | |
/** | |
* Update version and versionCode in capacitor Android and iOS | |
*/ | |
const appVersion = require("./package.json").version; | |
const appVersionSplitted = appVersion.split('.'); | |
const appVersionCode = appVersionSplitted[0] * 100000 + appVersionSplitted[1] * 1000 + appVersionSplitted[2] * 10 | |
// Android | |
replace({ | |
regex: /versionName \"([0-9]+\.?)*\"/, | |
replacement: "versionName \"" + appVersion + "\"", | |
paths: ['./android/app/build.gradle'], | |
silent: true | |
}); | |
replace({ | |
regex: /versionCode ([0-9]+\.?)*/, | |
replacement: "versionCode " + appVersionCode, | |
paths: ['./android/app/build.gradle'], | |
silent: true | |
}); | |
// iOS | |
replace({ | |
regex: /CURRENT_PROJECT_VERSION = ([0-9]+\.?)*;/g, | |
replacement: "CURRENT_PROJECT_VERSION = " + appVersion + ";", | |
paths: ['./ios/App/App.xcodeproj/project.pbxproj'], | |
silent: true, | |
multiline: true, | |
}); | |
replace({ | |
regex: /MARKETING_VERSION = ([0-9]+\.?)*;/g, | |
replacement: "MARKETING_VERSION = " + appVersion + ";", | |
paths: ['./ios/App/App.xcodeproj/project.pbxproj'], | |
silent: true, | |
multiline: true, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment