Keep your .env.example file up to date

Overview

Envy

Automate keeping your environment files in sync.

GitHub Tests Action Status PHPStan

How many times have you onboarded a new dev onto your team, only to have to spend ages debugging with them because your project's .env.example file is wildly outdated? Too many to count, if you're anything like us. Wouldn't it be nice if there were a way to ensure your environment files stay up to date? That's why we created Envy!

With a simple Artisan command, you can sync your environment files with your project config to keep everything fresh.

Installation

You can install the package via composer:

composer require worksome/envy --dev

We recommend publishing our config file, which allows you to fine-tune Envy to your project's requirements. You can do that using our install command:

php artisan envy:install

That's it! You're now ready to start using Envy.

Usage

Envy provides two commands: envy:sync and envy:prune. Let's break down how to use each of them.

php artisan envy:sync

CleanShot 2022-02-01 at 16 18 27@2x

This command combs through your project's config files for calls to Laravel's env function. After finding them all, it will compare them against your configured environment files (by default just your .env.example) for missing entries. If there are missing entries, you will be given the choice to either:

  1. Add the missing keys to your environment file
  2. Add the missing keys to Envy's blacklist

To learn more about configuring environment files, config files and blacklists, see the Configuration documentation.

The envy:sync command provides several options you might find helpful.

--path

If you'd like to run the sync command against a certain environment file, rather than your configured environment files, you may pass the path to the specified environment file using this option.

--dry

The --dry option will prevent the command from actually performing any updates. This is useful if you want to run Envy as part of a CI check without actually making updates. If missing entries were found, the command will fail, which would in turn fail the check in CI.

--force

If you want to automatically make changes to your configured environment files without being asked to confirm, you may pass the --force option. This is useful for CI bots, where you want to automate changes to your .env.example file, as no user input will be requested.

php artisan envy:prune

CleanShot 2022-02-02 at 12 03 51@2x

This command will search your project's configured environment files (by default just your .env.example) for entries that could not be found in any of the configured config files. If there are additional entries, you will be given the choice to either:

  1. Remove the additional entries from your environment file
  2. Add the missing keys to Envy's whitelist

To learn more about configuring environment files, config files and whitelists, see the Configuration documentation.

The envy:prune command provides several options you might find helpful.

--path

If you'd like to run the prune command against a certain environment file, rather than your configured environment files, you may pass the path to the specified environment file using this option.

--dry

The --dry option will prevent the command from actually pruning any environment variables. This is useful if you want to run Envy as part of a CI check without actually making updates. If additional entries were found, the command will fail, which would in turn fail the check in CI.

--force

If you want to automatically make changes to your configured environment files without being asked to confirm, you may pass the --force option. This is useful for CI bots, where you want to automate changes to your .env.example file, as no user input will be requested.

Configuration

You can customise Envy to suit your project's requirements using our envy.php config file. Here is a breakdown of the available options.

environment_files

Out of the box, Envy will only make changes to your .env.example file. If you want to add additional .env files, such as .env.testing or .env.dusk, you can append them to this array.

⚠️ We do not recommend adding your .env file to this array as it could cause unwanted side effects, particularly in CI.

config_files

By default, Envy will recursively scan all files in your project's config directory. For most projects, this will suffice. If your project makes env calls outside of config files (which is an anti-pattern), you should add the relevant files or directories to this array.

This is also useful if you make use of a package for which you have not published its config file. You may instead add an entry to this array that points to the base config file in the vendor directory.

Note that if you reference a directory instead of a file, it will include all files in that directory recursively.

display_comments

CleanShot 2022-02-01 at 16 28 42@2x

Some config keys, such as the one pictured above, may include comments. If you set display_comments to true, we will convert the config comment to an environment comment and place it above the relevant environment variable when inserting it into your configured environment files. This can be helpful in certain projects for remembering the purpose of various environment variables.

display_location_hints

When combing your config files, we make a note of the file and line where you called env. If you set display_location_hints to true, we will create a comment with this location information and place it above the relevant environment variable when inserting it into your configured environment files. This can be helpful in certain projects for locating the usage of various environment variables.

display_default_values

When combing your config files, we make a note of any default parameter set in the env call. For example, given a call for env('APP_NAME', 'Laravel'), the default would be 'Laravel'. If display_default_values is set to true, we will insert the default value as the value for the relevant environment variable when updating your configured environment files.

For obvious reasons, we will only insert scalar (primitive) types when copying default values.

⚠️ If you have exclude_calls_with_defaults set to true (which is the default), this option will have no effect because calls with defaults will be ignored.

exclude_calls_with_defaults

If you copy over every single call to env, your environment files will quickly become difficult to read. To help alleviate this, we provide the option to ignore calls to env that have default values provided. By default this is enabled, but setting this to false will let Envy sync environment variables that have defaults too.

blacklist

This array is a collection of environment keys that should never be synced to your environment files. By default, we include all Laravel environment variables that aren't included in the default .env file created when you first create a new Laravel project. Removing values from this array will cause them to be picked up again whilst syncing. Of course, if you have custom variables or variables provided by packages that you want to ignore, you may add them here.

If you select the Add to blacklist option when running php artisan envy:sync, this array will be updated with the environment variables listed by that command.

💡 You may still manually insert keys from your blacklist into your .env file. We won't remove them.

whitelist

This array is a collection of environment keys that we should never prune from your configured environment files, even if we cannot find reference to those variables in your configured config files. This can be useful for JS variables used by Laravel Mix, for example.

If you select the Add to whitelist option when running php artisan envy:prune, this array will be updated with the environment variables listed by that command.

Testing

Envy prides itself on a thorough test suite written in Pest, strict static analysis, and a very high level of code coverage. You may run these tests yourself by cloning the project and running our test script:

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.

Comments
  • Fails if no .env.example exists to begin with

    Fails if no .env.example exists to begin with

       ErrorException 
    
      file_get_contents(/Users/ajenbo/monorepo/projects/backoffice/backoffice-website/.env.example): Failed to open stream: No such file or directory
    
      at vendor/thecodingmachine/safe/generated/filesystem.php:319
        315▕         $result = \file_get_contents($filename, $use_include_path, $context, $offset);
        316▕     } elseif ($context !== null) {
        317▕         $result = \file_get_contents($filename, $use_include_path, $context);
        318▕     } else {
      ➜ 319▕         $result = \file_get_contents($filename, $use_include_path);
        320▕     }
        321▕     if ($result === false) {
        322▕         throw FilesystemException::createFromPhpError();
        323▕     }
    
          +4 vendor frames 
      5   [internal]:0
          Worksome\Envy\Envy::Worksome\Envy\{closure}("/Users/ajenbo/monorepo/projects/backoffice/backoffice-website/.env.example")
    
          +16 vendor frames 
      22  artisan:35
          Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    
    good first issue 
    opened by AJenbo 11
  • RuntimeException: None has no value

    RuntimeException: None has no value

    Running php artisan envy:sync yields a weird error:

    
       RuntimeException 
    
      None has no value.
    
      at vendor/phpoption/phpoption/src/PhpOption/None.php:45
         41▕     }
         42▕
         43▕     public function get()
         44▕     {
      ➜  45▕         throw new \RuntimeException('None has no value.');
         46▕     }
         47▕
         48▕     public function getOrCall($callable)
         49▕     {
    
          +1 vendor frames 
      2   [internal]:0
          Worksome\Envy\Actions\ReadEnvironmentFile::Worksome\Envy\Actions\{closure}()
    
          +4 vendor frames 
      7   [internal]:0
          Worksome\Envy\Envy::Worksome\Envy\{closure}()
    

    This is in laravel/framework v8.83.9 and worksome/envy v0.4.0

    opened by Jamesking56 5
  • Fix for #8 issue

    Fix for #8 issue

    If the '.env.example' didn't exist, the commands would fail.

    Now we check the environment list, loop through it, and if any of the files are not present we'll create them with a sample ".env.example".

    opened by AmirMehrabi 3
  • Add missing config value exclusions.

    Add missing config value exclusions.

    This PR adds three missing config variables that envy:sync suggests in a brand new Laravel 9 project.

    These are:

    # config/filesystem.php
    AWS_URL
    AWS_ENDPOINT
    
    # config/logging.php
    LOG_SLACK_WEBHOOK_URL
    
    opened by mdavis1982 3
  • Scout vars are skipped

    Scout vars are skipped

    Hi guys,

    I've just noticed that the SCOUT Env's are skipped, even though they are not in the exclusion list (envy.php). So I'm believing this is a bug. I'm expecting to get at least SCOUT_QUEUE and SCOUT_DRIVER. PS: config/scout.php is available. ;-)

    Is it a Bug, or do I miss something?

    Reproduce

    Install Scout. Remove SCOUT_QUEUE and SCOUT_DRIVER from env.example (if present) Run php artisan envy:sync

    Console-Output: There are no variables to sync!

    Environment

    Laravel Version ................................................................................................ 9.32.0
    PHP Version .................................................................................................... 8.1.10
    Composer Version ................................................................................................ 2.4.2
    Environment ..................................................................................................... local
    Debug Mode .................................................................................................... ENABLED

    ❯ composer show worksome/envy versions : * v0.5.0

    opened by hopkins385 2
  • Laravel support version needs to be increased

    Laravel support version needs to be increased

    See

    https://github.com/worksome/envy/blob/6722ca6604e3b8564d0ffed7139144e05bde88c2/src/Commands/SyncCommand.php#L69 uses Blade::render method, which was introduced in Laravel v8.80 (See https://github.com/laravel/framework/pull/40425)

    https://github.com/worksome/envy/blob/6722ca6604e3b8564d0ffed7139144e05bde88c2/composer.json#L20

    Trying to use the package on Laravel <8.80 will cause error:

      Call to undefined method Illuminate\View\Compilers\BladeCompiler::render()
    

    Need to set min. requirement to 8.80 in composer.json

    opened by a-bashtannik 2
  • Check .env.example's presence, create one if needed

    Check .env.example's presence, create one if needed

    So in the install command script, we will:

    1. check if .env.example is presence in the folder
    2. ask user, and create it if yes, else warn them to make one later. @lukeraymonddowning this will hopefully close this issue #8
    opened by sawirricardo 2
  • Support boolean values

    Support boolean values

    While trying out this package I noticed that boolean default values were not showing up in the .env.example file. Turns out that for whatever reason, the parser returns a node of Node\Expr\ConstFetch when the value is a boolean.

    If you feel that this check is now too permissive, I was thinking that I could check if the value of the ConstFetch was a boolean as well.

    Thanks for your consideration!

    opened by skylerkatz 2
  • Update Termwind Layouts

    Update Termwind Layouts

    This PR is similar to what I did for the Exchange package.

    • Makes use of new additions on Termwind like flex and justify-between.
    • Updates the Footer to match styling from both repos.
    • Changes the bullets to "⇁", similar from what is used on Laravel Route List.
    image image image image
    opened by xiCO2k 1
  •  Call to undefined function Termwind\ValueObjects\mb_strimwidth()

    Call to undefined function Termwind\ValueObjects\mb_strimwidth()

    I got error Call to undefined function mb_strimwidth() after command

     php artisan envy:sync ↙️
    
                                                            
      1 update for /.env.example                       1/1  
                                                            
    
     • CLOCKWORK_REQUESTS_SLOW_THRESHOLD 
    
    
     How would you like to handle these updates? [Add to environment file]:
      [0] Add to environment file
      [1] Add to exclusions
      [2] Cancel
     > 0
    
    
                                  
     Environment variables added! 
                                  
    
    
       **Error** 
    
      Call to undefined function Termwind\ValueObjects\mb_strimwidth()
    
      at vendor/nunomaduro/termwind/src/ValueObjects/Styles.php:933
        929▕      */
        930▕     private static function trimText(string $text, int $width): string
        931▕     {
        932▕         preg_match_all(self::STYLING_REGEX, $text, $matches, PREG_OFFSET_CAPTURE);
      ➜ 933▕         $text = rtrim(mb_strimwidth(preg_replace(self::STYLING_REGEX, '', $text) ?? '', 0, $width, '', 'UTF-8'));
        934▕ 
        935▕         foreach ($matches[0] ?? [] as [$part, $index]) {
        936▕             $text = substr($text, 0, $index).$part.substr($text, $index, null);
        937▕         }
    
          +21 vendor frames 
      22  artisan:37
          Illuminate\Foundation\Console\Kernel::handle()
    

    Enviroment: Ubuntu->WSL->Win10

    PHP 8.1.2 (cli) (built: Jan 24 2022 10:42:33) (NTS)
    Copyright (c) The PHP Group
    Zend Engine v4.1.2, Copyright (c) Zend Technologies
        with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies
        with Xdebug v3.1.2, Copyright (c) 2002-2021, by Derick Rethans
    

    composer

        "require": {
            "php": "^8.0.2",
            "laravel/framework": "^9.9.0",
            "laravel/sanctum": "^2.11",
            "laravel/tinker": "^2.5",
            "worksome/envy": "^0.3.1"
        },
        "require-dev": {
            "nunomaduro/collision": "^6.1.0",
    
    opened by dr41d45 1
  • Bump actions/checkout from 2 to 3

    Bump actions/checkout from 2 to 3

    Bumps actions/checkout from 2 to 3.

    Release notes

    Sourced from actions/checkout's releases.

    v3.0.0

    • Update default runtime to node16

    v2.4.0

    • Convert SSH URLs like org-<ORG_ID>@github.com: to https://github.com/ - pr

    v2.3.5

    Update dependencies

    v2.3.4

    v2.3.3

    v2.3.2

    Add Third Party License Information to Dist Files

    v2.3.1

    Fix default branch resolution for .wiki and when using SSH

    v2.3.0

    Fallback to the default branch

    v2.2.0

    Fetch all history for all tags and branches when fetch-depth=0

    v2.1.1

    Changes to support GHES (here and here)

    v2.1.0

    Changelog

    Sourced from actions/checkout's changelog.

    Changelog

    v2.3.1

    v2.3.0

    v2.2.0

    v2.1.1

    • Changes to support GHES (here and here)

    v2.1.0

    v2.0.0

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    opened by dependabot[bot] 1
Owner
Worksome
Building a future platform for flexible employment.
Worksome
I gues i tried to make a shell that's looks like a terminal in single php file

php-shell-gui Terms of service This tool can only be used for legal purposes. You take full responsibility for any actions performed using this. The o

Squar3 4 Aug 23, 2022
A compact command line utility for checking YAML file syntax

A compact command line utility for checking YAML file syntax. Uses the parsing facility of the Symfony Yaml Component.

John Fitzpatrick 12 Oct 25, 2022
A powerful command line application framework for PHP. It's an extensible, flexible component, You can build your command-based application in seconds!

CLIFramework CLIFramework is a command-line application framework, for building flexiable, simple command-line applications. Commands and Subcommands

Yo-An Lin 428 Dec 13, 2022
Render the symfony profiler toolbar in your terminal.

sourceability/console-toolbar-bundle Render the symfony profiler toolbar in your terminal. Each panel links to the corresponding web profiler page.

null 49 Nov 8, 2022
👨🏻‍🚀 A command-line tool that gives you the Alpine Day 2021 schedule in your timezone. 🚀

Alpine Day Schedule a command-line tool that gives you the Alpine Day 2021 schedule in your timezone. ?? Quick start Requires PHP 7.4+ # First, instal

Nuno Maduro 11 Jun 10, 2021
PHP Interminal is a command-line tool that gives you access to PHP Internals discussions in your terminal.

PHP Interminal is a command-line tool that gives you access to PHP Internals discussions in your terminal. ??

Nuno Maduro 32 Dec 26, 2022
Patrol is an elegant command-line tool that keeps your PHP Project's dependencies in check.

Patrol is an elegant command-line tool that keeps your PHP Project's dependencies in check. Installation / Usage Requires PHP 8.0+ First, install Patr

Nuno Maduro 237 Nov 14, 2022
Laracon Schedule a command-line tool that gives you the Laracon Online schedule in your timezone.

Laracon Schedule a command-line tool that gives you the Laracon Online schedule in your timezone. ?? Quick start Requires PHP 7.4+ # First, install: c

Nuno Maduro 101 Sep 16, 2022
Display your Laravel routes in the console, but make it pretty. 😎

Pretty Routes for Laravel Display your Laravel routes in the console, but make it pretty. ?? Installation You can install the package via composer: co

Alex 630 Dec 30, 2022
Backup your laravel database by a simple artisan command

Backup your laravel database by a simple artisan command This package will allow you to backup your laravel app database and you can also choose to se

Mohammed Omer 23 Feb 10, 2022
This command will guide you through upgrade your composer.json config rom version 1 to version 2.

Upgrade composer.json This command will guide you through upgrade your composer.json config rom version 1 to version 2. How to use: $ cd YOUR_PROJECT_

Ehsan Sabet 3 May 18, 2022
A CLI program that helps you check your endpoints by requesting the given servers and send a report message in any supported channel like Telegram

API Monitor A CLI program that help you check your endpoints by requesting the given servers and send a report message in any supported channel ( Tele

Hussein Feras 51 Aug 21, 2022
Supercharge your Symfony console commands!

zenstruck/console-extra A modular set of features to reduce configuration boilerplate for your commands: /** * Creates a user in the database. * *

Kevin Bond 29 Nov 19, 2022
Takeout is a CLI tool for spinning up tiny Docker containers, one for each of your development environment dependencies.

Takeout Takeout is a CLI tool for spinning up tiny Docker containers, one for each of your development environment dependencies. It's meant to be pair

Tighten 1.4k Jan 2, 2023
A Cli tool to save you time, and gives you the power to scaffold all of your models,controllers,commands

A Cli tool to save you time, and gives you the power to scaffold all of your models,controllers,commands... at once Installation You can install the p

Coderflex 16 Nov 11, 2022
A Laravel package that allows you to use multiple ".env" files in a precedent manner. Use ".env" files per domain (multi-tentant)!

Laravel Multi ENVs Use multiple .envs files and have a chain of precedence for the environment variables in these different .envs files. Use the .env

Allyson Silva 48 Dec 29, 2022
Keep your website up to date.

Deutsch English Svenska Update 0.8.88 Keep your website up to date. How to add extensions You can download extensions as ZIP files and copy them into

Anna 1 Oct 9, 2022
Date/Time Picker widget for Yii2 framework Based on Eonasdan's Bootstrap 3 Date/Time Picker

Yii2 Date/Time Picker Widget Date/Time Picker widget for Yii2 framework Based on Eonasdan's Bootstrap 3 Date/Time Picker Demo Since this is a part of

Yevhen Terentiev 8 Mar 14, 2022
Laravel Seeable - Keep track of the date and time a user was last seen.

Laravel Seeable This package makes it easy to keep track of the date and time a user was last seen. Installation Install this package. composer requir

Zep Fietje 29 Dec 26, 2022
⚙️ A WordPress plugin to set WordPress options from a .env file.

dotenv A WordPress plugin to set WordPress options from a .env file. Any WPENV_ prefixed variables in the .env will be used to override the WordPress

Brad Parbs 13 Oct 6, 2022