react-native-flavor-cli
v1.0.4
Published
this package will run your android react-native project based on you choice of flavors and dimensions
Downloads
7
Maintainers
Readme
react-native-flavor-cli
this package will run your android react-native project based on you choice of flavors and dimensions
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
rnf-cli clean-android
rnf-cli help [COMMAND]
rnf-cli init
rnf-cli reset
rnf-cli run-android
rnf-cli start
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