Git Product home page Git Product logo

react-native-npm-version's Introduction

react-native-npm-version

Example of React-Native application with version from package.json and npm version bump.

Why not to simpify cross-platform app version increase flow, with only npm version command ?

This repository provides an sample application, with integrated solution to minimize amount of monkey job with handling react-native applications.

Realization consist of few parts:

  • some script ./scripts/version.js which increase version in iOS project file Info.plist.
  • custom npm scripts version.
  • extended ./android/build.gradle
  • modified ./android/app/build.gradle:

To use those solution in your project,

  1. add version npm script to scripts section in your package.json:
{
  "scripts": {
    "version": "node ./scripts/version.js && [[ $(git status --porcelain -z | gawk '/version.json/ && /Info.plist/' ) ]] && git add version.json ios/"
  }
  1. copy ./scripts/version.js to your project root.
  2. extend ./android/app/build.gradle and ./android/build.gradle with the following samples:

./android/app/build.gradle

/* ... */
android {
  /* ... */
    defaultConfig {
        // Replace lines with your versionCode and versionName  with two lines below
        versionCode versionMajor * 10000 + versionMinor * 100 + versionPatch
        versionName "${versionMajor}.${versionMinor}.${versionPatch}"
        /* ... */
    }
  /* ... */
}

./android/build.gradle

subprojects {
    ext {
        def npmVersion = getNpmVersionArray()
        versionMajor = npmVersion[0]
        versionMinor = npmVersion[1]
        versionPatch = npmVersion[2]
    }
}

def getNpmVersion() {
    def inputFile = new File("../package.json")
    def packageJson = new JsonSlurper().parseText(inputFile.text)
    return packageJson["version"]
}

def getNpmVersionArray() { // major [0], minor [1], patch [2]
    def (major, minor, patch) = getNpmVersion().tokenize('.')
    return [Integer.parseInt(major), Integer.parseInt(minor), Integer.parseInt(patch)] as int[]
}

Based on solution by @AndrewJack https://github.com/AndrewJack/versioning-react-native-app. See Medium post

Requirements

  • gawk for macOS - used in npm run version
  • watchman for macOS
  • node higher than 4.2.0

react-native-npm-version's People

Contributors

szhigunov 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.