Skip to content

Instantly share code, notes, and snippets.

@jeremycastelli
Last active June 28, 2022 09:27
Show Gist options
  • Save jeremycastelli/8df74cd06b69a1c0c51f44f9e76de6c8 to your computer and use it in GitHub Desktop.
Save jeremycastelli/8df74cd06b69a1c0c51f44f9e76de6c8 to your computer and use it in GitHub Desktop.
capacitor update Android and iOS app version script
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