Skip to content

Latest commit

Β 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

envflare_cli

A modern CLI tool for managing flavor-based environment configurations in Flutter projects

A CLI tool to generate and manage flavor-based environment variable files for Flutter projects. Simplify environment configuration across different build flavors (development, staging, production) with schema validation and automated code generation.

✨ Features

  • 🍦 Flavor Management β€” Create, remove, and list environment flavors with ease
  • πŸ” Schema-Based Variables β€” Define environment variables in a centralized schema file
  • πŸ“ Environment Operations β€” Add, remove, set, and manage variables per flavor
  • βœ… Sync & Validate β€” Keep all flavors consistent and validate configurations
  • πŸ§™β€β™‚οΈ Interactive Wizard β€” Step-by-step guided setup for fast onboarding
  • πŸ’» Developer-Friendly β€” Intuitive CLI with helpful error messages
  • πŸ“‹ Code Generation β€” Generate type-safe Dart code from configuration files using envied

πŸ“‹ Table of Contents

πŸš€ Getting Started

Prerequisites

  • Dart SDK 3.4.0 or higher

Dependencies

To enable code generation features, add these to your pubspec.yaml:

dependencies:
  envied: ^1.3.4

dev_dependencies:
  build_runner: ^2.13.1
  envied_generator: ^1.3.4

Then install:

flutter pub get
# or
dart pub get

Note: The envied package provides:

  • πŸ“ Type-safe access with compile-time verification
  • πŸ”’ Configuration management for different flavors
  • πŸ“‹ Keeps .env out of source control if properly gitignored

πŸ“¦ Installation

From pub.dev (Recommended)

dart pub global activate envflare_cli

Verify installation:

envflare --help

πŸ“– Usage

πŸ§™β€β™‚οΈ Quick Start: Interactive Wizard (Recommended)

For a guided, interactive setup experience:

envflare wizard

This launches an interactive menu where you can:

Option Description
Initialize project with flavors and keys Set up your project from scratch with flavors and environment variables
Add a new flavor Add a new flavor (e.g., staging, prod) to your configuration
Add a new environment variable key Add a new environment variable to all flavors
Remove an environment variable key Remove an environment variable from all flavors

Initialize Project

envflare wizard
β†’ Select: "Initialize project with flavors and keys"

Guides you through creating and configuring your .env.schema and .envflare_cli.json.

Add a Flavor

envflare wizard
β†’ Select: "Add a new flavor"

Add a new flavor and set values for all existing environment keys.

Add an Environment Variable

envflare wizard
β†’ Select: "Add a new environment variable key"

Add a new variable to the schema and set values for all flavors.

Remove an Environment Variable

envflare wizard
β†’ Select: "Remove an environment variable key"

Remove a variable from all flavors and the schema.

⌨️ Manual Commands

For more control, use individual commands:

Initialize Project

envflare init

Creates .env.schema and .envflare_cli.json in your project root.

Flavor Management

# Add a new flavor
envflare flavor add development

# List all flavors
envflare flavor list

# Remove a flavor
envflare flavor remove development

Variable Management

# Add a variable to schema and all flavors
envflare add API_URL

# Set a variable for specific flavor
envflare set API_URL https://dev.api.com --flavor development

# Set a variable for all flavors
envflare set DEBUG true

# List variables for a flavor
envflare list --flavor development

# List all variables across flavors
envflare list

# Remove a variable from all flavors
envflare remove API_URL

Configuration Maintenance

# Sync variables across flavors (add missing ones)
envflare sync

# Validate all configurations
envflare validate

Code Generation

# Generate Dart code from .env files
envflare generate

Creates environment classes using the envied package for secure variable access. See Security section for details on how envied protects your environment variables.

πŸ“š Example Workflows

Option 1: Wizard-Based Setup (Fastest)

# Start the wizard
envflare wizard

# Follow the prompts to:
# 1. Initialize project
# 2. Add flavors (dev, staging, prod)
# 3. Add environment variables (API_URL, DEBUG_MODE, etc.)
# 4. Set values for each flavor
# 5. Generate code

Option 2: Manual Setup (More Control)

# 1. Initialize
envflare init

# 2. Add flavors
envflare flavor add dev
envflare flavor add prod

# 3. Add variables
envflare add API_BASE_URL
envflare add DEBUG_MODE

# 4. Set values
envflare set API_BASE_URL https://dev.api.com --flavor dev
envflare set API_BASE_URL https://prod.api.com --flavor prod
envflare set DEBUG_MODE true --flavor dev
envflare set DEBUG_MODE false --flavor prod

# 5. Generate code
envflare generate

πŸ“ Project Structure

After initialization, your project will have the following structure:

project-root/
β”œβ”€β”€ .env.schema              # Schema defining all environment variables
β”œβ”€β”€ .envflare_cli.json       # Configuration file with flavor list
└── .envs/
    β”œβ”€β”€ dev.env              # Development environment variables
    β”œβ”€β”€ staging.env          # Staging environment variables
    └── prod.env             # Production environment variables

File Descriptions

File Purpose
.env.schema Defines all available environment variable keys
.envflare_cli.json Stores flavor list and project configuration
.envs/*.env Contains environment variables for each flavor (local only, never commit to version control)

πŸ›‘οΈ Security

What envflare_cli + envied Provides

envflare_cli integrates with envied to improve configuration management and provide basic protection for environment values during development.

βœ… What It Helps With

  • Type-safe access β€” Compile-time verification of environment variables
  • Keeps .env files out of source control β€” Prevents accidental commits via .gitignore
  • Configuration per flavor β€” Manage different values for development, staging, production
  • Code obfuscation β€” Makes static extraction of values harder
  • Reduces accidental plaintext secrets β€” Keeps configuration out of source files
  • Non-sensitive configuration management β€” API base URLs, feature flags, app identifiers

⚠️ Important: Security Limitations

envied is NOT a secret vault.

Understand these limitations:

  1. Values may still be compiled into your binary β€” Code obfuscation makes extraction harder, but not impossible
  2. Code generation happens at build time β€” Values are read from .env during build_runner execution and embedded in generated code
  3. Determined attackers can recover values β€” With reverse engineering tools and effort, strings may be extractable
  4. Not suitable for high-security secrets β€” Use this only for non-sensitive configuration

Generated Code Details

The generated code from envflare generate:

  • Reads .env files at build time
  • Generates Dart source code with environment values
  • Applies code obfuscation to make extraction harder
  • Provides type-safe accessors for your configuration

🀝 Contributing

Contributions are welcome! To contribute:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ› Issues & Support

πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.

πŸ‘€ Author

Created with ❀️ by Muhammad Rizky


Made to simplify Flutter environment management

⬆ back to top

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages