UNPKG

rn-build-flavor-cli

Version:

CLI tool to add build flavors for React Native apps

112 lines (75 loc) โ€ข 2.48 kB
# rn-build-flavor-cli [![npm version](https://badge.fury.io/js/rn-build-flavor-cli.svg)](https://www.npmjs.com/package/rn-build-flavor-cli) [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![GitHub stars](https://img.shields.io/github/stars/paramababu/rn-build-flavor-cli?style=social)](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)