├── .gitignore ├── .npmignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── cli.js ├── package.json ├── prettier.config.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .vscode 3 | prettier.config.js 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### [1.1.1](https://github.com/ovos/dotenv-flow-cli/compare/v1.1.0...v1.1.1) (2024-01-07) 2 | 3 | - reduce package size by utilizing .npmignore 4 | 5 | ### [1.1.0](https://github.com/ovos/dotenv-flow-cli/compare/v1.0.0...v1.1.0) (2024-01-07) 6 | 7 | - variable expansion using `dotenv-expand` - allow `dotenv-flow-cli` to be a drop-in replacement for `dotenv-cli` ([#4]) 8 | - bump `minimist` dependency to `^1.2.6` 9 | 10 | [#4]: https://github.com/ovos/dotenv-flow-cli/pull/4 11 | 12 | ### 1.0.0 (2020-06-26) 13 | 14 | Initial release. 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dotenv-flow-cli 2 | 3 | This is a cli executable for [dotenv-flow](https://github.com/kerimdzhanov/dotenv-flow). 4 | 5 | ## Installing 6 | 7 | Either install it globally: 8 | 9 | ```bash 10 | $ npm install -g dotenv-flow-cli 11 | ``` 12 | 13 | or add to your project: 14 | 15 | Yarn 16 | ```bash 17 | $ yarn add dotenv-flow-cli 18 | ``` 19 | 20 | NPM 21 | ```bash 22 | $ npm install dotenv-flow-cli 23 | ``` 24 | 25 | ## Usage 26 | 27 | ```bash 28 | $ dotenv-flow 29 | ``` 30 | 31 | This will load the variables from the `.env*` files in the current working directory and then run the command (using the new set of environment variables). 32 | 33 | For more information about how the `.env*` files are loaded, please refer to [dotenv-flow docs](https://github.com/kerimdzhanov/dotenv-flow). 34 | 35 | ### Custom path 36 | You may specify a path where your `.env*` files are located with the `-p` option: 37 | ```bash 38 | $ dotenv-flow -p path/to/project 39 | ``` 40 | 41 | ### Arguments to the underlying command 42 | Put `--` separator before the command if it takes additional arguments, otherwise they might get lost. 43 | 44 | ```bash 45 | $ dotenv-flow -- my-command -p something 46 | ``` 47 | 48 | ### Variable expansion 49 | To allow it to be a drop-in replacement for [dotenv-cli](https://github.com/motdotla/dotenv-cli) variable interpolation (expanding) is automatically enabled using [dotenv-expand](https://github.com/motdotla/dotenv-expand) under the hood. 50 | 51 | For example: 52 | ``` 53 | IP=127.0.0.1 54 | PORT=1234 55 | APP_URL=http://${IP}:${PORT} 56 | ``` 57 | Using the above example `.env` file, `process.env.APP_URL` will be resolved to `http://127.0.0.1:1234`. 58 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const spawn = require('cross-spawn'); 3 | const argv = require('minimist')(process.argv.slice(2)); 4 | const dotenv = require('dotenv-flow'); 5 | const dotenvExpand = require('dotenv-expand'); 6 | 7 | function printHelp() { 8 | console.log( 9 | [ 10 | 'Usage: dotenv-flow [-p ] [-- command]', 11 | ' -p Path where `dotenv-flow` should read `.env*` files from. Defaults to current working directory.', 12 | ' command Command to run with ENV vars. Put `--` before the command if it takes additional arguments, otherwise they might get lost.', 13 | ].join('\n') 14 | ); 15 | } 16 | 17 | if (argv.help) { 18 | printHelp(); 19 | process.exit(); 20 | } 21 | 22 | const path = argv.p; 23 | dotenvExpand.expand(dotenv.config({ path })); 24 | 25 | const command = argv._[0]; 26 | if (!command) { 27 | printHelp(); 28 | process.exit(1); 29 | } 30 | 31 | spawn(command, argv._.slice(1), { stdio: 'inherit' }) 32 | .on('exit', function (exitCode) { 33 | process.exit(exitCode) 34 | }); 35 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dotenv-flow-cli", 3 | "version": "1.1.1", 4 | "description": "A cli executable to run commands with the ENV variables loaded by dotenv-flow", 5 | "license": "MIT", 6 | "repository": "github:ovos/dotenv-flow-cli", 7 | "bin": { 8 | "dotenv-flow": "./cli.js" 9 | }, 10 | "dependencies": { 11 | "cross-spawn": "^7.0.3", 12 | "dotenv-expand": "*", 13 | "dotenv-flow": "*", 14 | "minimist": "^1.2.6" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /prettier.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | singleQuote: true, 3 | trailingComma: 'es5', 4 | }; 5 | -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | cross-spawn@^7.0.3: 6 | version "7.0.3" 7 | resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" 8 | integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== 9 | dependencies: 10 | path-key "^3.1.0" 11 | shebang-command "^2.0.0" 12 | which "^2.0.1" 13 | 14 | dotenv-expand@*: 15 | version "10.0.0" 16 | resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-10.0.0.tgz#12605d00fb0af6d0a592e6558585784032e4ef37" 17 | integrity sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A== 18 | 19 | dotenv-flow@*: 20 | version "4.1.0" 21 | resolved "https://registry.yarnpkg.com/dotenv-flow/-/dotenv-flow-4.1.0.tgz#a78e79dcaf08a48200192eb5ed1e5af11062b861" 22 | integrity sha512-0cwP9jpQBQfyHwvE0cRhraZMkdV45TQedA8AAUZMsFzvmLcQyc1HPv+oX0OOYwLFjIlvgVepQ+WuQHbqDaHJZg== 23 | dependencies: 24 | dotenv "^16.0.0" 25 | 26 | dotenv@^16.0.0: 27 | version "16.3.1" 28 | resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e" 29 | integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ== 30 | 31 | isexe@^2.0.0: 32 | version "2.0.0" 33 | resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" 34 | integrity sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw== 35 | 36 | minimist@^1.2.6: 37 | version "1.2.8" 38 | resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c" 39 | integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA== 40 | 41 | path-key@^3.1.0: 42 | version "3.1.1" 43 | resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375" 44 | integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q== 45 | 46 | shebang-command@^2.0.0: 47 | version "2.0.0" 48 | resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea" 49 | integrity sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA== 50 | dependencies: 51 | shebang-regex "^3.0.0" 52 | 53 | shebang-regex@^3.0.0: 54 | version "3.0.0" 55 | resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" 56 | integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== 57 | 58 | which@^2.0.1: 59 | version "2.0.2" 60 | resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1" 61 | integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA== 62 | dependencies: 63 | isexe "^2.0.0" 64 | --------------------------------------------------------------------------------