Dotenv::Init

CircleCI

Copy over your .env.example in style.

Rationale

Typically, in any marginally complex app using dotenv, you'll have some step in new developer onboarding where you need to copy over a .env.example file to .env.

Also, in most Rails apps, gems, and other setups, you typically have a bin/setup script that will do its best to automate the app bootstrapping process for freshly cloned copies.

This is an attempt to harmonize these two concepts by creating a user-friendly automated flow for filling in .env.

Installation

To install globally and run anywhere:

gem install dotenv-init

Or, to use in your project (i.e., in bin/setup):

gem "dotenv-init", group: :development

# Optional: enable colors
gem "colorize"

Usage

Given a .env.example like this:

# Facebook credentials can be found in the 1Password Vault.
# Create a test app specifically for your local copy of this
# app and then grab its app ID.
export FACEBOOK_APP_ID=

# This is the password used as a backdoor to the admin
# console in the event the client locks themselves out (again).
# Regenerate with `rake secret`, or just use the default in development:
export ADMIN_PASSWORD=hunter2

Running dotenv-init will present you with a prompt interactively walking you through filling these values in, providing defaults when they're given:

Facebook credentials can be found in the 1Password Vault.
Create a test app specifically for your local copy of this
app and then grab its app ID.
FACEBOOK_APP_ID: 110318327925842

This is the password used as a backdoor to the admin
console in the event the client locks themselves out (again).
Regenerate with `rake secret`, or just use the default in development:
ADMIN_PASSWORD: (hunter2) hunter3

Providing all of the values will populate .env with the exact same formatting as your .env.example, including comments and whitespace.

Contributing

  1. Fork this repo
  2. Add your feature in a branch
  3. Open a pull request

Before making a commit, please run rake spec and rubocop to ensure it will pass CI.

Please write good commit messages, be polite, and be open to discussing ways to improve on the code you've contributed.

Architecture

For details on how the parser works, check out dotenv's parser as well as comment_aware_parser_spec.rb. This project's parser simply subclasses dotenv's parser to add more functionality.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dotenv-assigner.

License

The gem is available as open source under the terms of the MIT License.