flavor_cli 0.0.2
flavor_cli: ^0.0.2 copied to clipboard
Production-grade Flutter flavor automation CLI
🍹 Flavor CLI #
Transform any Flutter project into a multi-environment powerhouse in seconds.
flavor_cli is a production-grade automation tool that handles the heavy lifting of build flavor configuration. Stop manually editing build.gradle or Xcode schemes; focus on shipping features instead.
✨ Key Features #
🛡️ Resilient & Type-Safe #
- Zero-Guess Configuration: Auto-generates a type-safe
AppConfigclass with typed variables (String,bool,int,double). - Project Safety: Interactive
deleteandreplacecommands ensure your project remains buildable. Revert instantly with aresetcommand.
📦 Flexible Architecture #
- Automatic Isolation: Automatically configures unique internal suffixes (e.g.,
.dev,.beta) to allow parallel app installations on the same device. - Smart Patterns: Seamlessly supports both the professional "Separate Mains" pattern and the classic "Single Main" approach.
- IDE Integration: Automatically generates and maintains VS Code
launch.jsonconfigurations for each flavor, allowing you to run any environment directly from your IDE.
🚀 Getting Started #
1. Installation #
Add flavor_cli to your dev_dependencies:
flutter pub add dev:flavor_cli
2. Initialization #
Launch the interactive wizard to bootstrap your project:
dart run flavor_cli init
3. Usage Overview #
Usage: flavor_cli <command> [arguments]
Commands:
init Initialize flavor setup in your project
add Add a new flavor to an existing setup
delete Remove an existing flavor
replace Rename an existing flavor
reset Cleanup project from any flavors and revert to standard state
run Run the project with a specific flavor
build Build the project with a specific flavor
firebase Setup Firebase for all flavors automatically
Examples:
dart run flavor_cli init
dart run flavor_cli add staging
dart run flavor_cli replace
dart run flavor_cli reset
dart run flavor_cli run dev
dart run flavor_cli build apk prod
dart run flavor_cli firebase
Tip
See it in action: Check out the example project for a pre-configured implementation.
🛠️ Command Deep Dive #
1. init #
The wizard will guide you through:
- Flavor Selection: Choose standard sets (dev, prod) or enter manually.
- Schema Definition: Define your
AppConfigvariables (e.g.,String baseUrl). - Config Location: Specify where your generated configuration file should live.
- Main Strategy: Choose between Separate Mains (one file per flavor) or Single Main.
- App Branding: Set the display name for your application (auto-detected).
- Production Identity: Identify which flavor is your "Golden" production build.
- Package ID: Set your base application identifier (auto-detected from Gradle).
Note
Zero-Config Isolation: flavor_cli now automatically applies unique package identifiers for each flavor to ensure they can be installed side-by-side on devices.
2. add #
Add a new environment to an existing setup without re-initializing.
- The wizard will guide you through: Prompting for the flavor name if not provided as an argument.
- Outcome: Generates new
.xcconfig, updates Android flavors, and adds the flavor to yourAppConfigenum.
3. delete #
Safely remove a flavor and its associated artifacts.
- The wizard will guide you through: Selecting the flavor to remove.
- Safety First: If deleting a flavor would leave only one remaining, the tool warns you of system damage and offers a full Project Reset.
- Identity Migration: If you delete your production flavor, you'll be prompted to nominate a new one.
4. replace #
Rename an existing flavor across the entire project.
- The wizard will guide you through:
- Selecting the old flavor.
- Entering the new name.
- Outcome: Renames files, updates class definitions, and migrates Xcode schemes/schematics automatically.
5. reset #
- Action: Reverts your project to its original, non-flavored state.
- Cleanup: Removes all flavor mains, XCConfigs, generated scripts, and reverts
build.gradleand Xcode project settings.
6. run #
Standardized wrapper for the flutter run command.
- The wizard will guide you through:
- Selecting the flavor (if not provided).
- Selecting the build mode (debug, release, or profile).
- Outcome: Launches the app on your selected device with the correct flavor and entry point.
7. build #
High-level wrapper for the flutter build command.
- The wizard will guide you through:
- Selecting the build target (apk, ipa, appbundle, etc.) if not provided.
- Selecting the flavor to build.
- Outcome: Generates a production-ready binary for the specified platform.
8. firebase #
The "One-Pass" Firebase orchestrator.
- The wizard will guide you through:
- Selecting your Firebase project strategy.
- Entering your Firebase Project IDs.
- Outcome:
- Automatically resets and authenticates via
firebase login. - Runs
flutterfire configurefor every flavor with correct mappings. - Automated Initialization: Injects Firebase setup code and imports into your
mainfiles automatically.
- Automatically resets and authenticates via
💡 Pro Tips #
Separate Mains Pattern #
By default, flavor_cli creates separate main files (e.g., lib/main/main_dev.dart). This is the safest way to handle flavors as it ensures environment-specific code is only compiled for that specific flavor.
📚 Guides #
- Firebase Integration - A step-by-step guide to using Firebase CLI with flavors.
- Manual Setup Guide - A beginner-friendly reference for manual flavor configuration on Android and iOS.
🤝 Contributing #
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.