|
6 | 6 | [![Coverage Status][ico-scrutinizer]][link-scrutinizer]
|
7 | 7 | [![Quality Score][ico-code-quality]][link-code-quality]
|
8 | 8 |
|
9 |
| -EnvDiff is tool to compare environment keys to find the difference between .env files and actualize them |
| 9 | +EnvDiff is tool to compare environment keys to find the difference between .env files and actualize them. |
10 | 10 |
|
11 |
| -# Usage |
| 11 | +# Installation |
12 | 12 |
|
13 |
| -composer Scripts composer event |
| 13 | +``` |
| 14 | +composer install tekill/env-diff |
| 15 | +``` |
| 16 | + |
| 17 | +## Manual running |
| 18 | +### Actualize variables |
| 19 | +Compare `.env` with `.env.dist` and add missing variables to `.env` file |
| 20 | +``` |
| 21 | +php ./vendor/bin/env-diff actualize |
| 22 | +``` |
| 23 | + |
| 24 | +Compare `.env` with `.env.example` and add missing variables to `.env` file |
| 25 | +``` |
| 26 | +php ./vendor/bin/env-diff actualize .env.example |
| 27 | +``` |
| 28 | + |
| 29 | +Compare `.env-target` with `.env.example` and add missing variables to `.env-target` file |
| 30 | +``` |
| 31 | +php ./vendor/bin/env-diff actualize .env.example .env-target |
| 32 | +``` |
| 33 | + |
| 34 | +If you want to delete outdated values just run command with `-k=false` option |
| 35 | + |
| 36 | +``` |
| 37 | +php ./vendor/bin/env-diff actualize -k=false |
| 38 | +``` |
| 39 | + |
| 40 | +### Show differences |
| 41 | +Command has same interface, arguments and options |
| 42 | + |
| 43 | +Compare `.env` with `.env.dist` and show differences between them |
| 44 | +``` |
| 45 | +php ./vendor/bin/env-diff diff |
| 46 | +``` |
| 47 | + |
| 48 | +## Composer script |
| 49 | + |
| 50 | +Add code block in `composer.json`: |
14 | 51 | ```$json
|
15 | 52 | "scripts": {
|
16 | 53 | "post-update-cmd": "Lf\\EnvDiff\\Composer\\ScriptHandler::actualizeEnv"
|
17 | 54 | }
|
18 | 55 | ```
|
| 56 | + |
| 57 | +The `.env` will then be created or updated by the composer script, to match the structure of the dist |
| 58 | +file `.env.dist` by asking you the missing variables. |
| 59 | + |
| 60 | +By default, the dist file is assumed to be in the same place than the target `.env` |
| 61 | +file, suffixed by `.dist`. This can be changed in the configuration: |
| 62 | + |
| 63 | +```json |
| 64 | +{ |
| 65 | + "extra": { |
| 66 | + "lf-env-diff": [ |
| 67 | + { |
| 68 | + "dist": "path/to/env.dist", |
| 69 | + "target": "path/to/.env" |
| 70 | + } |
| 71 | + ] |
| 72 | + } |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +The script handler will ask you interactively for variables which are missing |
| 77 | +in the target env file, using the value of the dist file as default value. |
| 78 | +If composer is run in a non-interactive mode `--no-interaction`, the values of the dist file |
| 79 | +will be used for missing variables. |
| 80 | + |
| 81 | +**Warning:** This handler will overwrite any comments or spaces into your target `.env` file so handle with care. |
| 82 | + |
| 83 | +### Managing multiple ignored files |
| 84 | + |
| 85 | +The handler can manage multiple ignored files. To use this feature, the `lf-env-diff` extra should contain a |
| 86 | +JSON array with multiple configurations inside it instead of a configuration object: |
| 87 | + |
| 88 | +```json |
| 89 | +{ |
| 90 | + "extra": { |
| 91 | + "lf-env-diff": [ |
| 92 | + { |
| 93 | + "dist": "path/to/.env.dist", |
| 94 | + "target": "path/to/.env" |
| 95 | + }, |
| 96 | + { |
| 97 | + "dist": "path/to/.env.dist", |
| 98 | + "target": "path/to/.env-test", |
| 99 | + "keep-outdated": false |
| 100 | + } |
| 101 | + ] |
| 102 | + } |
| 103 | +} |
| 104 | +``` |
| 105 | + |
| 106 | +### Show difference |
| 107 | + |
| 108 | +Add code block in `composer.json`: |
| 109 | +```$json |
| 110 | +"scripts": { |
| 111 | + "post-update-cmd": "Lf\\EnvDiff\\Composer\\ScriptHandler::showDifference" |
| 112 | +} |
| 113 | +``` |
| 114 | + |
| 115 | +This handler has same behavior as described before. |
| 116 | + |
| 117 | +## Git hooks |
| 118 | + |
| 119 | +You can use Git hook that gets triggered after any 'git pull' whenever one of the files specified has changed. |
| 120 | +Useful to update any web application dependency or sync configuration. |
| 121 | + |
| 122 | +Create `post-merge` hook in `.git/hooks` directory of your project: |
| 123 | +``` |
| 124 | +#/usr/bin/env bash |
| 125 | +
|
| 126 | +changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)" |
| 127 | +
|
| 128 | +check_run() { |
| 129 | + echo "$changed_files" | grep -E --quiet "$1" && eval "$2" |
| 130 | +} |
| 131 | +
|
| 132 | +# Aclualize env files if the `env.dist` file gets changed |
| 133 | +check_run env.dist "php ./vendor/bin/env-diff aclualize" |
| 134 | +``` |
| 135 | + |
19 | 136 | [ico-version]: https://img.shields.io/packagist/v/Tekill/env-diff.svg?style=flat-square
|
20 | 137 | [ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
|
21 | 138 | [ico-travis]: https://img.shields.io/travis/Tekill/env-diff/master.svg?style=flat-square
|
|
0 commit comments