Skip to content

Commit c539bf1

Browse files
committed
Congrats, you found the first commit!
0 parents  commit c539bf1

8 files changed

Lines changed: 578 additions & 0 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
lib
2+
.idea
3+
node_modules
4+
yarn-error.log
5+
*.iml

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
*.iml
3+
yarn-error.log

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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.

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "react-native-cli-bump-version",
3+
"version": "1.0.0",
4+
"main": "src/index.ts",
5+
"types": "lib/index.d.ts",
6+
"license": "MIT",
7+
"scripts": {
8+
"build": "tsc",
9+
"prepare": "rm -rf ./lib/* && yarn build"
10+
},
11+
"dependencies": {
12+
"chalk": "3.0.0",
13+
"ramda": "0.27.0"
14+
},
15+
"devDependencies": {
16+
"@types/node": "^13.9.1",
17+
"ts-node": "8.6.2",
18+
"typescript": "3.8.3"
19+
}
20+
}

react-native.config.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const { versioner } = require('./lib/index')
2+
3+
module.exports = {
4+
commands: [{
5+
name: 'bump-version',
6+
func: (_, config, args) => {
7+
8+
if (args.skipCodeFor === 'all' && args.skipSemverFor === 'all') {
9+
// https://i.kym-cdn.com/photos/images/newsfeed/001/240/075/90f.png
10+
console.log('My work here is done.')
11+
return
12+
}
13+
14+
versioner({
15+
root: config.root,
16+
pbxprojPath: config.project.ios.pbxprojPath,
17+
buildGradlePath: config.project.android.buildGradlePath,
18+
type: args.type,
19+
skipCodeFor: args.skipCodeFor
20+
? args.skipCodeFor.split(' ')
21+
: [],
22+
skipSemVerFor: args.skipSemverFor
23+
? args.skipSemverFor.split(' ')
24+
: []
25+
})
26+
},
27+
options: [
28+
{
29+
name: '--type [major|minor|patch]',
30+
description: 'SemVer release type, optional if --skip-semver is true'
31+
},
32+
{
33+
name: '--skip-semver-for [android|ios|all]',
34+
description: 'Skips bump SemVer for specified platform'
35+
},
36+
{
37+
name: '--skip-code-for [android|ios|all]',
38+
description: 'Skips bump version codes for specified platform'
39+
}
40+
]
41+
}]
42+
}

0 commit comments

Comments
 (0)