Giter Site home page Giter Site logo

grohden / react-native-cli-bump-version Goto Github PK

View Code? Open in Web Editor NEW
38.0 3.0 11.0 212 KB

A simple react native cli plugin to help you with version bumps

JavaScript 25.63% TypeScript 74.37%
react-native cli versioning plugin react-native-cli react-native-cli-plugin bumps

react-native-cli-bump-version's Introduction

react-native-cli-bump-version

A simple react-native cli plugin to bump versions at platform files

Install

npm i --save-dev react-native-cli-bump-version

yarn add -D react-native-cli-bump-version

Usage

Since this is a react-native cli plugin, after adding it to the project you can call:

npx react-native bump-version --type patch

That should produce this:

iOS project.pbxproj code: 24 -> 25
Android build.gradle code: 23 -> 24
iOS project.pbxproj version: 1.10.6 -> 1.10.7
Android gradle.build version: 1.10.6 -> 1.10.7
package.json: 1.10.6 -> 1.10.7

The plugin updates and write the output listed files, and it's up to you to commit them.

Tip: I usually create a script entry for the command, since it tends to be long:

{
    "scripts": {
        "bump": "npx react-native bump-version --skip-semver-for android"
    }
}

That way you can invoke it like: yarn bump --type patch

Flags

Just ask for help:

npx react-native bump-version --help

Options:
  --type [major|minor|patch]           SemVer release type, optional if --skip-semver-for all is passed
  --skip-semver-for [android|ios|all]  Skips bump SemVer for specified platform
  --skip-code-for [android|ios|all]    Skips bump version codes for specified platform
  --semver                             Pass release version if known. Overwrites calculated SemVer. Optional.
  -h, --help                           output usage information

Recommendations

Use gradle for SemVer sync

Android can handle automatically semantic version sync with package.json:

import groovy.json.JsonSlurper

def getNpmVersion() {
    def inputFile = file("$rootDir/../package.json")
    def jsonPackage = new JsonSlurper().parseText(inputFile.text)

    return jsonPackage["version"]
}

android {
  ...
  defaultConfig {
        applicationId "com.example"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 25
        versionName getNpmVersion()
        ...
    }
    ...
}

Note: with this you should pass --skip-semver-for android, otherwise the cli will break.

Use MARKETING_VERSION in Info.plist

I've choosen to remove the Info.plist manipulation as it was not needed if it uses the MARKETING_VERSION env var, so be sure that your project/xcode is updated and that the Info.plist file has MARKETING_VERSION instead of SemVer string:

	<key>CFBundleShortVersionString</key>
	<string>$(MARKETING_VERSION)</string>

Mention

I tried to find a tool that did this before starting it:

  • rnbv inspired my initial sources
  • react-native-version actually does what I was looking for, but I already had written the tool, so I just published it anyway.

react-native-cli-bump-version's People

Contributors

andreieuganox avatar grohden avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-native-cli-bump-version's Issues

Feature: Indicate project on iOS

My mobile app have two xcode projects:

  • ios/AppOne.xcodeproj
  • ios/AppTwo.xcodeproj

So when I bump the version, the version is bumped only in one project (randomly).
So my question is: is it possible to update only one project indicating the folder? or update multiple folders?
Do you have the interest to allow this option? I can help to implement

Not working with React Native 0.69

The command has stopped working after upgrading my project to RN 0.69. It seems that the property, config.project.ios.pbxprojPath has been removed from react-native.config.js. The following patch fixes this.

diff --git a/node_modules/react-native-cli-bump-version/react-native.config.js b/node_modules/react-native-cli-bump-version/react-native.config.js
index fe5274e..6197368 100644
--- a/node_modules/react-native-cli-bump-version/react-native.config.js
+++ b/node_modules/react-native-cli-bump-version/react-native.config.js
@@ -10,16 +10,14 @@ module.exports = {
                 console.log("My work here is done.");
                 return;
             }
-
             const appGradlePath = path.join(
                 config.project.android.sourceDir,
                 config.project.android.appName,
                 "build.gradle",
             );
-
             versioner({
                 root: config.root,
-                pbxprojPath: config.project.ios.pbxprojPath,
+                pbxprojPath: `${config.project.ios.sourceDir}/${config.project.ios.xcodeProject.name.replace(".xcworkspace",".xcodeproj")}/project.pbxproj`,
                 buildGradlePath: appGradlePath,
                 type: args.type,
                 semver: args.semver,

Bump removes versionName identifier from build.gradle

Hi! First of all, thanks for this wonderful tool -- it really comes in handy!

I've noticed that after running a version bump, the versionName identifier is removed from the build.gradle file.

Say that these are my initial build.gradle contents:

    defaultConfig {
        applicationId "com.my.project"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 3
        versionName "0.3.0"
    }

I will run:

> λ npx react-native bump-version --type minor

iOS project.pbxproj code: 3 -> 4
Android build.gradle code: 3 -> 4
iOS project.pbxproj version: undefined -> 0.4.0
Android gradle.build version: "0.3.0" -> 0.4.0
package.json: 0.3.0 -> 0.4.0

This is the final build.gradle:

    defaultConfig {
        applicationId "com.my.project"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 4
        "0.4.0"
    }

Which in turns, makes the script fail on the next try, because it doesn't find the versionName identifier:

> λ npx react-native bump-version --type minor

iOS project.pbxproj code: 4 -> 5
Android build.gradle code: 4 -> 5
iOS project.pbxproj version: undefined -> 0.5.0
error Cannot read property 'replace' of undefined. Run CLI with --verbose flag for more details.
TypeError: Cannot read property 'replace' of undefined
    at BuildGradleManager.setVersionName (C:\MyProject\node_modules\react-native-cli-bump-version\lib\index.js:92:17)
    at ProjectFilesManager.syncSemver (C:\MyProject\node_modules\react-native-cli-bump-version\lib\index.js:139:83)
    at ProjectFilesManager.exec (C:\MyProject\node_modules\react-native-cli-bump-version\lib\index.js:167:18)
    at exports.versioner (C:\MyProject\node_modules\react-native-cli-bump-version\lib\index.js:176:38)
    at Object.func (C:\MyProject\node_modules\react-native-cli-bump-version\react-native.config.js:21:13)
    at Command.handleAction (C:\MyProject\node_modules\@react-native-community\cli\build\index.js:186:23)
    at Command.listener (C:\MyProject\node_modules\@react-native-community\cli\node_modules\commander\index.js:315:8)
    at Command.emit (events.js:200:13)
    at Command.parseArgs (C:\MyProject\node_modules\@react-native-community\cli\node_modules\commander\index.js:651:12)
    at Command.parse (C:\MyProject\node_modules\@react-native-community\cli\node_modules\commander\index.js:474:21)

I think this might simply be a wrong replacement in the regex. (If there is a chance, I might come back myself with a PR for this issue.)

Thanks again!

Bump is broken if no version is specified

Hi!

I came across an issue where specifying some options would actually fail to do any processing on the files.

λ yarn bump:minor
yarn run v1.22.5
$ react-native bump-version --type minor --skip-code-for all
iOS project.pbxproj version: 0.6.0 -> function(str, flags) {
  if (arguments.length === 0) return this._version;
  this._version = str;
  flags = flags || '-V, --version';
  var versionOption = new Option(flags, 'output the version number');
  this._versionOptionName = versionOption.long.substr(2) || 'version';
  this.options.push(versionOption);
  this.on('option:' + this._versionOptionName, function() {
    process.stdout.write(str + '\n');
    process.exit(0);
  });
  return this;
}
error flags.indexOf is not a function. Run CLI with --verbose flag for more details.
TypeError: flags.indexOf is not a function
    at new Option (C:\Projects\<myProject>\node_modules\commander\index.js:46:25)
    at Command.version (C:\Projects\<myProject>\node_modules\commander\index.js:855:23)
    at String.replace (<anonymous>)
    at BuildGradleManager.setVersionName (C:\Projects\<myProject>\node_modules\react-native-cli-bump-version\lib\index.js:95:40)
    at ProjectFilesManager.syncSemver (C:\Projects\<myProject>\node_modules\react-native-cli-bump-version\lib\index.js:151:83)
    at ProjectFilesManager.dryRun (C:\Projects\<myProject>\node_modules\react-native-cli-bump-version\lib\index.js:195:18)
    at ProjectFilesManager.run (C:\Projects\<myProject>\node_modules\react-native-cli-bump-version\lib\index.js:169:14)
    at exports.versioner (C:\Projects\<myProject>\node_modules\react-native-cli-bump-version\lib\index.js:202:38)
    at Object.func (C:\Projects\<myProject>\node_modules\react-native-cli-bump-version\react-native.config.js:25:13)
    at Command.handleAction (C:\<myProject>\node_modules\@react-native-community\cli\build\index.js:191:23)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I traced the problem down to the use of the new version flag, which is read from args.version. The problem here is that the Commander package does not pass pure objects as args, but rather a Command object. That object does not have a key for version, but has a version() method attached to the prototype, which is the code that you see in the console output.

I have tested this with:

  • react-native-cli-bump-version 1.0.4
  • commander 2.20.3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.