rn-build-flavor-cli
Version:
CLI tool to add build flavors for React Native apps
112 lines (75 loc) โข 2.48 kB
Markdown
# rn-build-flavor-cli
[](https://www.npmjs.com/package/rn-build-flavor-cli)
[](LICENSE)
[](https://github.com/paramababu/rn-build-flavor-cli)
CLI to automatically create Android/iOS build flavors for React Native projects with `.env` support and `react-native-config` integration.
## ๐ Features
- ๐ Creates `android/app/src/<flavor>` folder with manifest and strings
- ๐ Injects flavor into `build.gradle` (`productFlavors`)
- ๐ Generates `ios/GoogleService-Info-<flavor>.plist`
- ๐ฑ Creates `.env.<flavor>` file using a customizable template
- ๐ง Injects `require('react-native-config')` into `App.js` or `App.tsx`
- ๐ฆ Auto-installs `react-native-config` using npm/yarn/pnpm (based on lock files)
- ๐ Automatically adds run script to `package.json` like:
```json
"android-staging": "npx react-native run-android --variant=stagingDebug"
```
## ๐ฆ Installation
```bash
npm install -g rn-build-flavor-cli
```
## ๐ ๏ธ Usage
### Create a new flavor
```bash
npx rn-build-flavor-cli create staging \
--package=com.myapp.staging \
--name="MyApp Staging"
```
## ๐ฒ How to Run a Flavor
Once created, a script is added to your `package.json`. You can run the app using:
```bash
yarn android-staging
# or
npm run android-staging
```
This will internally run:
```bash
npx react-native run-android --variant=stagingDebug
```
โ ๏ธ **Note:** Do not name your flavor `test` โ it's a reserved word in Gradle and will break the build.
## ๐ Resulting Structure
```
android/app/src/staging/
โโโ AndroidManifest.xml
โโโ res/values/strings.xml
ios/
โโโ GoogleService-Info-staging.plist
.env.staging
App.js (or App.tsx)
โโโ require('react-native-config') injected
```
## ๐งช Template Support
You can customize `.env` by creating:
```
templates/env.example
```
```env
API_URL=https://api.YOUR_FLAVOR.example.com
APP_ENV=YOUR_FLAVOR
```
This will be used and replaced automatically.
## ๐ง Auto Dependency Detection
The CLI will detect your project setup and use:
- `yarn add react-native-config`
- `pnpm add react-native-config`
- `npm install react-native-config`
## ๐ License
MIT ยฉ [paramababu](https://github.com/paramababu)