Code Monkey home page Code Monkey logo

react-native-version's Introduction

react-native-version Build Status

Seamlessly shadows the behaviour of npm version.

Prerequisites

  • Xcode Command Line Tools (xcode-select --install)

Project setup

Open your Xcode project and under "Build Settings -> Versioning -> Current Project Version", set the value to your current CFBundleVersion ("General -> Identity -> Build").


npm-scripts hook (automatic method)

Setup

npm install react-native-version --save
# or
yarn add react-native-version

Hook into the "version" or "postversion" npm script in your app's package.json:

{
	"name": "AwesomeProject",
	"version": "0.0.1",
	"private": true,
	"scripts": {
		"start": "node node_modules/react-native/local-cli/cli.js start",
		"postversion": "react-native-version"
	},
	// ...
}

Usage

Before you publish a new build of your app, run npm version <newversion>.

react-native-version will then update your android/ and ios/ code. Depending on the script and options you choose, it can also automatically amend the version bump commit and update the Git tag created by npm version. This method should be useful in most cases. If you need more control, take a look at the CLI and options below.

CLI

Setup

npm install -g react-native-version
# or
yarn global add react-native-version

Example usage

cd AwesomeProject/
npm version patch
react-native-version

Options

-h, --help                output usage information
-V, --version             output the version number
-a, --amend               Amend the previous commit. Also updates the latest Git tag to point to the amended commit. This is done automatically when react-native-version is run from the "version" or "postversion" npm script. Use "--never-amend" if you never want to amend.
--skip-tag                For use with "--amend", if you don't want to update Git tags.
-A, --never-amend         Never amend the previous commit.
-b, --increment-build     Only increment build number.
-d, --android [path]      Path to your "android/app/build.gradle" file.
-i, --ios [path]          Path to your "ios/" folder.
-q, --quiet               Be quiet, only report errors.
-r, --reset-build         Reset build number back to "1" (iOS only). Unlike Android's "versionCode", iOS doesn't require you to bump the "CFBundleVersion", as long as "CFBundleShortVersionString" changes. To make it consistent across platforms, react-native-version bumps both by default. You can use this option if you prefer to keep the build number value at "1" after every version change. If you then need to push another build under the same version, you can use "-bt ios" to increment.
-t, --target <platforms>  Only version specified platforms, eg. "--target android,ios".

You can apply these options to the "version" or "postversion" script too. If for example you want to commit the changes made by RNV yourself, add the "--never-amend" option:

{
	// ...
	"scripts": {
		"postversion": "react-native-version --never-amend"
	},
	// ...
}

Targeting platforms

The default behaviour is to version all React Native platforms. You can target specific platforms by passing a comma-separated list to the "--target" option, or by using the RNV environment variable:

RNV=android,ios npm version patch
# or
RNV=android,ios react-native-version

When using the CLI, you can even combine both methods and make your teammates rage ๐Ÿ˜ˆ :suspect::

RNV=android react-native-version --target ios

:rage1: ๐Ÿ™Š

API

import { version } from 'react-native-version';

async function doSomething() {
	const versionResult = await version({
		amend: true,
		// ...
	});
}

// or

version({
	amend: true,
	// ...
})
.then(commitHash => {
	console.log(commitHash);
})
.catch(err => {
	console.error(err);
});

Methods

version(program, projectPath) โ‡’ Promise.<(string|Error)>

Versions your app

Kind: global function
Returns: Promise.<(string|Error)> - A promise which resolves with the last commit hash

Param Type Description
program Object commander/CLI-style options, camelCased
projectPath string Path to your React Native project

Types

Promise

Custom type definition for Promises

Kind: global typedef
Properties

Name Type Description
result * See the implementing function for the resolve type and description
result Error Rejection error object

See also

react-native-version's People

Contributors

stovmascript avatar nicinabox avatar

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.