Giter Site home page Giter Site logo

react-native-flavor-cli's Introduction

react-native-flavor-cli

this package will run your android react-native project based on you choice of flavors and dimensions

oclif Version Downloads/week License

Setup

First install the react-native-flavor-cli in global mode

  npm install -g react-native-flavor-cli

OR

  yarn global add react-native-flavor-cli

and then add needed gradle task to the android/app/build.gradle file

task saveRnfcliData () {
   group "rnfcli"
   def flavorsDetail = []
   def dimensions = []
   doLast {
       android.productFlavors.all {flavor ->
           def temp = ["${flavor.name}" , "${flavor.dimension}"]
           flavorsDetail.add(temp)
           if(!dimensions.contains("${flavor.dimension}")){
               dimensions.add("${flavor.dimension}")
           }
       }
       def flavorDetailsJson = JsonOutput.toJson(flavorsDetail)
       println flavorDetailsJson
       def productFlavorsFile = new File("../flavors.json")
       productFlavorsFile.deleteOnExit()

       productFlavorsFile.write(flavorDetailsJson.toString())

       def dimensionsJson = JsonOutput.toJson(dimensions)
       def dimensionsFile = new File("../dimensions.json")
       dimensionsFile.deleteOnExit()
       dimensionsFile.write(dimensionsJson.toString())
   }
}

and then import groovy.json.JsonOutput in android/app/build.gradle file your android/app/build.gradle should be somthing like this :

apply plugin: "com.android.application"

import com.android.build.OutputFile
import groovy.json.JsonOutput
...
...
...
...
...
task saveRnfcliData () {
   group "rnfcli"
   def flavorsDetail = []
   def dimensions = []
   doLast {
       android.productFlavors.all {flavor ->
           def temp = ["${flavor.name}" , "${flavor.dimension}"]
           flavorsDetail.add(temp)
           if(!dimensions.contains("${flavor.dimension}")){
               dimensions.add("${flavor.dimension}")
           }
       }
       def flavorDetailsJson = JsonOutput.toJson(flavorsDetail)
       println flavorDetailsJson
       def productFlavorsFile = new File("../flavors.json")
       productFlavorsFile.deleteOnExit()

       productFlavorsFile.write(flavorDetailsJson.toString())

       def dimensionsJson = JsonOutput.toJson(dimensions)
       def dimensionsFile = new File("../dimensions.json")
       dimensionsFile.deleteOnExit()
       dimensionsFile.write(dimensionsJson.toString())
   }
}
preBuild.dependsOn(saveRnfcliData)

Important

and then sync gradle in android studio, new task will be added to rnfcli group in gradle panel, when gradle sync finished open gradle panel and open app -> rnfcli, right click on saveRnfcliData and choose Execute Before Build.

after all these steps open a cmd/terminal in your react-native project root directory and run this command :

rnf-cli init

Usage

$ npm install -g react-native-flavor-cli
$ rnf-cli COMMAND
running command...
$ rnf-cli (-v|--version|version)
react-native-flavor-cli/1.0.4 darwin-x64 node-v8.11.4
$ rnf-cli --help [COMMAND]
USAGE
  $ rnf-cli COMMAND
...

Commands

rnf-cli build-android

Generate Apk based on your flavor choices

USAGE
  $ rnf-cli build-android

DESCRIPTION
  ...
  This command will ask you name of product flavors based on dimensions from build.gradle file and then generates new 
  apk for you.

See code: src/commands/build-android.js

rnf-cli clean-android

Cleans Your Android Project

USAGE
  $ rnf-cli clean-android

DESCRIPTION
  ...
  This will run gradle clean in android folder of your react-native project

See code: src/commands/clean-android.js

rnf-cli help [COMMAND]

display help for rnf-cli

USAGE
  $ rnf-cli help [COMMAND]

ARGUMENTS
  COMMAND  command to show help for

OPTIONS
  --all  see all commands in CLI

See code: @oclif/plugin-help

rnf-cli init

Setup Rnf-cli in you react-native project

USAGE
  $ rnf-cli init

OPTIONS
  -e, --entryfile=entryfile  react-native project entry file

DESCRIPTION
  ...
  This will create new rnf-config.json in your root folder of your project, please add this to your git.

See code: src/commands/init.js

rnf-cli reset

This will run react-native start -- --reset-cache

USAGE
  $ rnf-cli reset

DESCRIPTION
  ...
  Command for reseting metro bundler and restarting it.

See code: src/commands/reset.js

rnf-cli run-android

This will run your react-native android project based on your product flavor choices

USAGE
  $ rnf-cli run-android

OPTIONS
  -f, --fresh=fresh  use fresh run options, user true or false

DESCRIPTION
  ...
  For running your react-native android app with rnf-cli please follow the steps in documentation.

See code: src/commands/run-android.js

rnf-cli start

This will run react-native start in your current working directory (process.cwd)

USAGE
  $ rnf-cli start

DESCRIPTION
  ...
  Please make sure you are in the right project folder when you want to use this command.

See code: src/commands/start.js

rnf-cli build-android

Generate Apk based on your flavor choices

USAGE
  $ rnf-cli build-android

DESCRIPTION
  ...
  This command will ask you name of product flavors based on dimensions from build.gradle file and then generates new
  apk for you.

See code: src/commands/build-android.js

rnf-cli clean-android

Cleans Your The Android Project

USAGE
  $ rnf-cli clean-android

DESCRIPTION
  ...
  This will run gradle clean in andorid folder of your react-native project

See code: src/commands/clean-android.js

rnf-cli help [COMMAND]

display help for rnf-cli

USAGE
  $ rnf-cli help [COMMAND]

ARGUMENTS
  COMMAND  command to show help for

OPTIONS
  --all  see all commands in CLI

See code: @oclif/plugin-help

rnf-cli init

Setup Rnf-cli in you react-native project

USAGE
  $ rnf-cli init

OPTIONS
  -e, --entryfile=entryfile  react-native project entry file

DESCRIPTION
  ...
  This will create new rnf-config.json in your root folder of your project, please add this to your git.

See code: src/commands/init.js

rnf-cli reset

This will run react-native start -- --reset-cache

USAGE
  $ rnf-cli reset

DESCRIPTION
  ...
  Command for reseting metro bundler and restarting it.

See code: src/commands/reset.js

rnf-cli run-android

This will run your react-native android project based on your product flavor choices

USAGE
  $ rnf-cli run-android

OPTIONS
  -f, --fresh=fresh  use fresh run options, user true or false

DESCRIPTION
  ...
  For running your react-native android app with rnf-cli please follow the steps in documentation.

See code: src/commands/run-android.js

rnf-cli start

This will run react-native start in your current working directory (process.cwd)

USAGE
  $ rnf-cli start

DESCRIPTION
  ...
  Please make sure you are in the right project folder when you want to use this command.

See code: src/commands/start.js

react-native-flavor-cli's People

Stargazers

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