|
| 1 | +# react-native-cli-bump-version |
| 2 | + |
| 3 | +A **simple** react-native cli plugin to bump versions at platform files |
| 4 | + |
| 5 | +## Install |
| 6 | + |
| 7 | +`npm i --save-dev react-native-cli-bump-version` |
| 8 | + |
| 9 | +`yarn add -D react-native-cli-bump-version` |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +Since this is a react-native cli plugin, after adding it to the project |
| 14 | +you can call: |
| 15 | + |
| 16 | +```shell script |
| 17 | +npx react-native bump-version --type patch |
| 18 | +``` |
| 19 | +That should produce this: |
| 20 | +```shell script |
| 21 | +iOS project.pbxproj code: 24 -> 25 |
| 22 | +Android build.gradle code: 23 -> 24 |
| 23 | +iOS project.pbxproj version: 1.10.6 -> 1.10.7 |
| 24 | +Android gradle.build version: 1.10.6 -> 1.10.7 |
| 25 | +package.json: 1.10.6 -> 1.10.7 |
| 26 | +``` |
| 27 | + |
| 28 | +The plugin updates and write the output listed files, and it's up to you to |
| 29 | +commit them. |
| 30 | + |
| 31 | +## Flags |
| 32 | + |
| 33 | +Just ask for help: |
| 34 | + |
| 35 | +```shell script |
| 36 | +npx react-native bump-version --help |
| 37 | + |
| 38 | +Options: |
| 39 | + --type [major|minor|patch] SemVer release type, optional if --skip-semver is true |
| 40 | + --skip-semver-for [android|ios|all] Skips bump SemVer for specified platform |
| 41 | + --skip-code-for [android|ios|all] Skips bump version codes for specified platform |
| 42 | + -h, --help output usage information |
| 43 | +``` |
| 44 | +
|
| 45 | +### Recommendations |
| 46 | +
|
| 47 | +#### Use gradle for SemVer sync |
| 48 | +Android can handle automatically semantic version sync with `package.json`: |
| 49 | +
|
| 50 | +```groovy |
| 51 | +import groovy.json.JsonSlurper |
| 52 | + |
| 53 | +def getNpmVersion() { |
| 54 | + def inputFile = file("$rootDir/../package.json") |
| 55 | + def jsonPackage = new JsonSlurper().parseText(inputFile.text) |
| 56 | + |
| 57 | + return jsonPackage["version"] |
| 58 | +} |
| 59 | + |
| 60 | +android { |
| 61 | + ... |
| 62 | + defaultConfig { |
| 63 | + applicationId "com.example" |
| 64 | + minSdkVersion rootProject.ext.minSdkVersion |
| 65 | + targetSdkVersion rootProject.ext.targetSdkVersion |
| 66 | + versionCode 25 |
| 67 | + versionName getNpmVersion() |
| 68 | + ... |
| 69 | + } |
| 70 | + ... |
| 71 | +} |
| 72 | +``` |
| 73 | +
|
| 74 | +Note: with this you should pass `--skip-semver-for android`, otherwise the cli |
| 75 | +will break. |
| 76 | +
|
| 77 | +#### Use MARKETING_VERSION in `Info.plist` |
| 78 | +
|
| 79 | +I've choose to remove the `Info.plist` manipulation as it was not needed |
| 80 | +if it uses the `MARKETING_VERSION` env var, so be sure that your project/xcode is updated and that |
| 81 | +the `Info.plist` file has `MARKETING_VERSION` instead of SemVer string: |
| 82 | +
|
| 83 | +```xml |
| 84 | + <key>CFBundleShortVersionString</key> |
| 85 | + <string>$(MARKETING_VERSION)</string> |
| 86 | +``` |
| 87 | +
|
| 88 | +### Mention |
| 89 | +
|
| 90 | +I tried to find a tool that did this before starting it: |
| 91 | + |
| 92 | + * [rnbv](https://github.com/llotheo/react-native-cli-bump-version) inspired my initial sources |
| 93 | + * [react-native-version](https://github.com/stovmascript/react-native-version) actually does what I was |
| 94 | + looking for, but I already had written the tool, so I just published it anyway. |
0 commit comments