Why not to simpify cross-platform app version increase flow, with only npm version command ?
This repository provides an sample application, with integrated solution to minimize amount of monkey job with handling react-native applications.
Realization consist of few parts:
- some script
./scripts/version.jswhich increase version in iOS project fileInfo.plist. - custom npm scripts
version. - extended
./android/build.gradle - modified
./android/app/build.gradle:
- add
versionnpm script toscriptssection in yourpackage.json:
{
"scripts": {
"version": "node ./scripts/version.js && [[ $(git status --porcelain -z | gawk '/version.json/ && /Info.plist/' ) ]] && git add version.json ios/"
}- copy
./scripts/version.jsto your project root. - extend
./android/app/build.gradleand./android/build.gradlewith the following samples:
./android/app/build.gradle
/* ... */
android {
/* ... */
defaultConfig {
// Replace lines with your versionCode and versionName with two lines below
versionCode versionMajor * 10000 + versionMinor * 100 + versionPatch
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
/* ... */
}
/* ... */
}./android/build.gradle
subprojects {
ext {
def npmVersion = getNpmVersionArray()
versionMajor = npmVersion[0]
versionMinor = npmVersion[1]
versionPatch = npmVersion[2]
}
}
def getNpmVersion() {
def inputFile = new File("../package.json")
def packageJson = new JsonSlurper().parseText(inputFile.text)
return packageJson["version"]
}
def getNpmVersionArray() { // major [0], minor [1], patch [2]
def (major, minor, patch) = getNpmVersion().tokenize('.')
return [Integer.parseInt(major), Integer.parseInt(minor), Integer.parseInt(patch)] as int[]
}Based on solution by @AndrewJack https://github.com/AndrewJack/versioning-react-native-app. See Medium post
gawkfor macOS - used innpm run versionwatchmanfor macOSnodehigher than 4.2.0