# react-native-version-auto

> Version your React Native or Expo app in a `npm version` fashion.

Latest version **0.1.0** (published 2023-07-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-version-auto
pnpm add react-native-version-auto
yarn add react-native-version-auto
bun add react-native-version-auto
```

Provides the command `react-native-version-auto`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2023-07-20 |
| First published | 2023-07-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 13 |
| Unpacked size | 31.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Martin Stovicek |
| Maintainers | zhouweibo |
| Keywords | CFBundleShortVersionString, CFBundleVersion, CRNA, CURRENT_PROJECT_VERSION, agvtool, build, buildNumber, bump, create-react-native-app, expo, gradle, info, npm-version, plist, react-native, semver, version, versionCode, versionName |

## Links

- npm: https://www.npmjs.com/package/react-native-version-auto
- Repository: https://github.com/weber-cd/react-native-version-auto
- Homepage: https://github.com/weber-cd/react-native-version-auto#readme
- Issues: https://github.com/weber-cd/react-native-version-auto/issues
- npm.io page: https://npm.io/package/react-native-version-auto

## Dependencies (13)

- [chalk](https://npm.io/package/chalk.md) ^4.1.0
- [plist](https://npm.io/package/plist.md) ^3.0.1
- [dottie](https://npm.io/package/dottie.md) ^2.0.0
- [semver](https://npm.io/package/semver.md) ^7.0.0
- [p-settle](https://npm.io/package/p-settle.md) ^4.0.0
- [commander](https://npm.io/package/commander.md) ^6.0.0
- [common-tags](https://npm.io/package/common-tags.md) ^1.4.0
- [js-beautify](https://npm.io/package/js-beautify.md) ^1.7.4
- [lodash.uniq](https://npm.io/package/lodash.uniq.md) ^4.5.0
- [pbxproj-dom](https://npm.io/package/pbxproj-dom.md) ^1.0.11
- [resolve-from](https://npm.io/package/resolve-from.md) ^5.0.0
- [detect-indent](https://npm.io/package/detect-indent.md) ^6.0.0
- [lodash.flattendeep](https://npm.io/package/lodash.flattendeep.md) ^4.4.0

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2023-07-20

## README

forked from ancon-labs/react-native-version

# react-native-version

[![license](https://badgen.net/github/license/stovmascript/react-native-version)](https://github.com/stovmascript/react-native-version/blob/master/LICENSE)
[![npm](https://badgen.net/npm/v/react-native-version)](https://www.npmjs.com/package/react-native-version)
[![test](https://github.com/stovmascript/react-native-version/workflows/Test/badge.svg)](https://github.com/stovmascript/react-native-version/actions)
[![david](https://badgen.net/david/dep/stovmascript/react-native-version)](https://github.com/stovmascript/react-native-version/network/dependencies)

Seamlessly shadows the behaviour of [`npm version`](https://docs.npmjs.com/cli/version).

## npm-scripts hook (automatic method)

### Setup

```bash
$ npm install react-native-version --save-dev
# or
$ yarn add react-native-version --dev
```

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

```diff
{
  "name": "AwesomeProject",
  "version": "0.0.1",
  "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

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

### Example usage

```bash
$ cd AwesomeProject/
$ npm version patch
$ react-native-version
```

## Options

<!-- START cli -->

    -V, --version                         output the version number
    -a, --amend                           Amend the previous 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. Also, if the previous commit is
    a valid npm-version commit,
    react-native-version will update the
    Git tag pointing to this commit.
    --skip-tag                            For use with "--amend", if you don't
    want to update Git tags. Use this
    option if you have git-tag-version set
    to false in your npm config or you use
    "--no-git-tag-version" during
    npm-version.
    -A, --never-amend                     Never amend the previous commit.
    -b, --increment-build                 Only increment build number.
    -B, --never-increment-build           Never increment build number.
    -d, --android [path]                  Path to your "android/app/build.gradle"
    file. (default:
    "android/app/build.gradle")
    -i, --ios [path]                      Path to your "ios/" folder. (default:
    "ios")
    -L, --legacy                          Version iOS using agvtool (macOS only).
    Requires Xcode Command Line Tools.
    -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.
    -s, --set-build <number>              Set a build number. WARNING: Watch out
    when setting high values. This option
    follows Android's app versioning
    specifics - the value has to be an
    integer and cannot be greater than
    2100000000. You cannot decrement this
    value after publishing to Google Play!
    More info at:
    https://developer.android.com/studio/publish/versioning.html#appversioning
    --generate-build                      Generate build number from the package
    version number. (e.g. build number for
    version 1.22.3 will be 1022003)
    -t, --target <platforms>              Only version specified platforms, e.g.
    "--target android,ios".
    --allow-invalid-short-version-string  Allow invalid value for
    CFBundleShortVersionString. (e.g.
    1.5.0-staging.1.
    -h, --help                            display help for command

<!-- END cli -->

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:

```diff
{
  "scripts": {
-   "postversion": "react-native-version"
+   "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:

```bash
$ 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 :smiling_imp: :suspect:

```bash
$ RNV=android react-native-version --target ios
```

:rage1: :speak_no_evil:

## Custom version commit message

When updating Git tags, RNV uses the version commit message to find the correct Git tag. If you're running `npm version` with the `-m` or `--message` option, make sure your message includes `%s`, which will be replaced with the resulting version number. For example:

```bash
$ npm version patch -m "Upgrade to %s for reasons"
```

If you're using yarn, you can configure the commit message generated by `yarn version` though `yarn config set version-git-message` - see the [docs](https://yarnpkg.com/lang/en/docs/cli/version/#toc-git-tags).

The behavior can be also adjusted by `.npmrc` and `.yarnrc` config files.

## API

```javascript
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);
  });
```

<!-- START api -->

### Functions

<dl>
<dt><a href="#version">version(program, projectPath)</a> ⇒ <code>Promise.&lt;(string|Error)&gt;</code></dt>
<dd><p>Versions your app</p>
</dd>
</dl>

### Typedefs

<dl>
<dt><a href="#Promise">Promise</a></dt>
<dd><p>Custom type definition for Promises</p>
</dd>
</dl>

<a name="version"></a>

### version(program, projectPath) ⇒ <code>Promise.&lt;(string\|Error)&gt;</code>

Versions your app

**Kind**: global function  
**Returns**: <code>Promise.&lt;(string\|Error)&gt;</code> - A promise which resolves with the last commit hash

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

<a name="Promise"></a>

### Promise

Custom type definition for Promises

**Kind**: global typedef  
**Properties**

| Name   | Type               | Description                                                        |
| ------ | ------------------ | ------------------------------------------------------------------ |
| result | <code>\*</code>    | See the implementing function for the resolve type and description |
| result | <code>Error</code> | Rejection error object                                             |

<!-- END api -->

## Known issues

### `SyntaxError: Expected """, "\'", "\"", "\n", or [^\"] but "\" found.`

When running `react-native link` on Windows, native modules will be linked in your Xcode project with paths that include backslashes (`\`) instead of forward slashes (`/`). This will break `pbxproj-dom`, which we rely on to parse Xcode projects. To fix this issue, convert any `LIBRARY_SEARCH_PATHS` and `HEADER_SEARCH_PATHS` as shown in [this comment](https://github.com/stovmascript/react-native-version/issues/52#issuecomment-393343784). This step could be automated with a library like [normalize-path](https://www.npmjs.com/package/normalize-path) or [unixify](https://www.npmjs.com/package/unixify).

## See also

- [agvtool](https://developer.apple.com/library/content/qa/qa1827/_index.html)
- [npm-version](https://docs.npmjs.com/cli/version)
- [Semantic Versioning (semver)](http://semver.org/)
- [ionic-version](https://github.com/stovmascript/ionic-version)

---
_Source: https://npm.io/package/react-native-version-auto · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
