flavored_env 0.5.0 copy "flavored_env: ^0.5.0" to clipboard
flavored_env: ^0.5.0 copied to clipboard

A utility to generate matching dotenv and dart configuration files.

flavored_env #

ci coverage pub package License: MIT

Generate and synchronize dotenv and dart configuration classes for your firebase application.

Flavored_env is useful if you need to maintain a common set of constants between your cloud functions and your flutter application. It generates dotenv files for your cloud function deployments as well as corresponding dart class for your application. It supports flavors and the ability to create copies in multiple locations.

The tools was developed for a personal project to help keep constants in sync during development. Hopefully it can be helpful to others. Do let me know if you are interested in additional features.

Features #

  • Manage all application and cloud constants in single file
  • Create dotenv and Dart classes from configuration
  • Supports multiple flavors, copies and locations

Installation #

This package is intended to support development of Dart projects with [package:build][]. In general, put it under [dev_dependencies][], in your [pubspec.yaml][pubspec].

dev_dependencies:
  build_runner:

Built-in Commands #

The flavord_env package exposes a binary by the same name, which can be invoked using dart run flavored_env <command>.

The available commands are

  • create-yaml: create a sample flavored_env.yaml file.
  • generate: generate the configuration files based on yaml file edits and does rebuilds as necessary.

flavored_env.yaml #

Create a template flavored_env.yaml in your project root by running:

pub run flavored_env --create-yaml

The default sample will look like this

# flavored_env example

dotenv_to:  
  # list of existing subfolders where to generate the .env files. 
  - lib/config
  - functions

class_to:
  # List of existing subfolders where to generate the dart config files.
  - lib  # (default)
  - lib/config

# Name of the dart class to encaspulate all the constants. The same class
# is generated for each flavor, but the file name will have a _<flavor> suffix  
class_name: EnvConfig

flavors:
# List of application flavors. 
  default:
  # The default flavor will become .env.default 
    keys:
      user_collection_name:              # key name
        value: "users"                   # key value
        info: "user collection name"     # optional info to keep with the output.   

      show_exception_on_crash:
        value: false
        info: "display exception to users upon app crash"
        
      additional_debug_timeout:
        value: 0
        info: "additional timeout added to the app for testing"
        
  development:
    # The development flavor will become .env.development 
    keys:
      # the collection name will be propagated from the 'default' configuration for dart. 

      show_exception_on_crash: # overriden constant for development.
        value: true
        info: "display exception to users upon app crash"
        
      additional_debug_timeout: # overriden constant for development.
        value: 0
        info: "additional timeout added to the app for testing"

      slack_url: 
        value: https://slack.com/abcd_dev
        info: webhook url for development environment
  beta:
    keys:
      slack_url: 
        value: https://slack.com/jkdl_beta
        info: webhook url for development environment
        
  production:
    keys:
      slack_url: 
        value: https://slack.com/xyz_production
        info: webhook url for development environment
      
      fancy_value_prod_only:
        value: 42
        info: constant only available in production

After config is specified in YAML file run following command

pub run flavored_env --generate

Yaml Specification #

dotenv_to to indicate the list of relative paths where to create the dotenv files.

class_to to indicate the list of relative paths where to create the dart files.

class_name to specivy the name of the class to use, default to EnvConfig

flavors to specify each flavor or development environment

default environment (optional) is used for the base configuration. Its content will be used to generate .env.default. When generating the dart files for other flavors, the keys from the default environment that are not overriden are merged to make sure all constants are available to your flutter app.

keys to specify the list of constants for the specific environment. Each key is specified by its name and can take two attributes; value that represents the constant value to use and info that provides one line descriptions that will be used as comments in the generated files.

Upon generation, the key names will be converted to camel case for the dart files and upper case separated by underscore for the dotenv to match normal conventions.

Any environment listed in the file will translate into .env.environment and env_config_environment.dart in each of the specified locations.

Limitations #

  • Destination paths are relative only. No absolute paths
  • Destination paths must exist and are not created
  • Opiniated format for keys in dart and dotenv for now
0
likes
120
pub points
0%
popularity

Publisher

unverified uploader

A utility to generate matching dotenv and dart configuration files.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

args, dart_style, logging, path, pub_updater, recase, yaml

More

Packages that depend on flavored_env