Comparing version 8.0.2 to 9.0.0
#! /usr/bin/env node | ||
require('../lib').EnvCmd(process.argv.slice(2)) | ||
require('../dist').CLI(process.argv.slice(2)) |
# Changelog | ||
## 9.0.0 | ||
- ***BREAKING***: Converted project to Typescript | ||
- ***BREAKING***: Changes to all option flags, see docs for new options | ||
- ***BREAKING***: Dropping support for node v4 and v6 | ||
- **Change**: Updated all dependencies | ||
- **Change**: Update package-lock.json file | ||
- **Feature**: Added support for asynchronous .env and .rc files | ||
- **Feature**: Added support for a programmatic API | ||
- **Feature**: Added --use-shell option (thanks to nidkil) | ||
- **Fix**: Keep newline (`\n`) characters intact when parsing env files | ||
- **Change**: Added node v10 and v12 to build automation | ||
- **Change**: Updated Readme file to reflect new options and CLI changes | ||
## 8.0.2 | ||
@@ -3,0 +16,0 @@ - **Change**: Updated dependencies and packages.json to fix `npm audit` concerns. |
{ | ||
"name": "env-cmd", | ||
"version": "8.0.2", | ||
"version": "9.0.0", | ||
"description": "Executes a command using the envs in the provided env file", | ||
"main": "lib/index.js", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"engines": { | ||
"node": ">=4.0.0" | ||
"node": ">=8.0.0" | ||
}, | ||
@@ -13,7 +14,8 @@ "bin": { | ||
"scripts": { | ||
"test": "mocha", | ||
"test": "mocha -r ts-node/register ./test/**/*.ts", | ||
"test-cover": "nyc --reporter=lcov --reporter=text npm test", | ||
"test-lint": "standard", | ||
"test-lint": "eslint ./src/**/*.ts ./test/**/*.ts", | ||
"coveralls": "coveralls < coverage/lcov.info", | ||
"lint": "standard --fix" | ||
"lint": "eslint --fix ./src/**/*.ts ./test/**/*.ts", | ||
"build": "tsc" | ||
}, | ||
@@ -45,13 +47,44 @@ "repository": { | ||
"dependencies": { | ||
"cross-spawn": "^6.0.5" | ||
"commander": "^2.20.0", | ||
"cross-spawn": "6.0.5" | ||
}, | ||
"devDependencies": { | ||
"better-assert": "^1.0.2", | ||
"coveralls": "^3.0.1", | ||
"mocha": "^5.1.1", | ||
"nyc": "^11.8.0", | ||
"proxyquire": "^2.0.1", | ||
"sinon": "^5.0.7", | ||
"standard": "^11.0.1" | ||
"@types/chai": "4.1.7", | ||
"@types/cross-spawn": "6.0.0", | ||
"@types/mocha": "5.2.6", | ||
"@types/node": "^12.0.0", | ||
"@types/sinon": "^7.0.11", | ||
"@typescript-eslint/eslint-plugin": "^1.7.0", | ||
"@typescript-eslint/parser": "^1.7.0", | ||
"chai": "4.2.0", | ||
"coveralls": "3.0.3", | ||
"eslint": "^5.16.0", | ||
"eslint-config-standard-with-typescript": "^7.0.0", | ||
"eslint-plugin-import": "^2.17.2", | ||
"eslint-plugin-node": "^9.0.1", | ||
"eslint-plugin-promise": "^4.1.1", | ||
"eslint-plugin-standard": "^4.0.0", | ||
"mocha": "^6.1.4", | ||
"nyc": "^14.1.0", | ||
"sinon": "^7.3.2", | ||
"ts-node": "^8.1.0", | ||
"typescript": "^3.4.5" | ||
}, | ||
"nyc": { | ||
"include": [ | ||
"src/**/*.ts" | ||
], | ||
"extension": [ | ||
".ts" | ||
], | ||
"require": [ | ||
"ts-node/register" | ||
], | ||
"reporter": [ | ||
"text-summary", | ||
"html" | ||
], | ||
"sourceMap": true, | ||
"instrument": true | ||
} | ||
} |
146
README.md
@@ -16,3 +16,3 @@ [![Travis](https://img.shields.io/travis/toddbluhm/env-cmd.svg)](https://travis-ci.org/toddbluhm/env-cmd) | ||
**Environment file `./test/.env`** | ||
**Environment file `./.env`** | ||
``` | ||
@@ -29,56 +29,37 @@ # This is a comment | ||
"scripts": { | ||
"test": "env-cmd ./test/.env mocha -R spec" | ||
"test": "env-cmd mocha -R spec" | ||
} | ||
} | ||
``` | ||
or | ||
**Terminal** | ||
```sh | ||
./node_modules/.bin/env-cmd ./test/.env node index.js | ||
./node_modules/.bin/env-cmd node index.js | ||
``` | ||
## Advanced Usage | ||
### `--fallback` file usage option | ||
You can specify an `.env.local` (or any name) env file, add that to your `.gitignore` and use that in your local development environment. Then you can use a regular `.env` file in root directory with production configs that can get committed to a private/protected repo. When `env-cmd` cannot find the `.env.local` file it will fallback to looking for a regular `.env` file. | ||
**Environment file `./.env.local`** | ||
## 📜 Help | ||
``` | ||
# This is a comment | ||
ENV1=THANKS | ||
ENV2=FOR ALL | ||
ENV3=THE FISH | ||
``` | ||
**Fallback Environment file `./.env`** | ||
``` | ||
# This can be used as an example fallback | ||
ENV1=foo | ||
ENV2=bar | ||
ENV3=baz | ||
ENV4=quux | ||
ENV5=gorge | ||
``` | ||
Usage: _ [options] <command> [...args] | ||
**Package.json** | ||
uses `./.env` as a fallback | ||
```json | ||
{ | ||
"scripts": { | ||
"test": "env-cmd --fallback ./.env.local mocha -R spec" | ||
} | ||
} | ||
Options: | ||
-v, --version output the version number | ||
-f, --file [path] Custom env file file path (default path: ./.env) | ||
-r, --rc-file [path] Custom rc file path (default path: ./.env-cmdrc(|.js|.json) | ||
-e, --environments [env1,env2,...] The rc file environment(s) to use | ||
--fallback Fallback to default env file path, if custom env file path not found | ||
--no-override Do not override existing environment variables | ||
--use-shell Execute the command in a new shell with the given environment | ||
-h, --help output usage information | ||
``` | ||
or | ||
**Terminal** | ||
```sh | ||
# uses ./.env as a fallback, because it can't find `./.env.local` | ||
./node_modules/.bin/env-cmd ./.env.local node index.js | ||
``` | ||
## 🔬 Advanced Usage | ||
### `.rc` file usage | ||
For more complex projects, a `.env-cmdrc` file can be defined in the root directory and supports as many environments as you want. Instead of passing the path to a `.env` file to `env-cmd`, simply pass the name of the environment you want to use thats in your `.env-cmdrc` file. You may also use multiple environment names to merge env vars together. | ||
For more complex projects, a `.env-cmdrc` file can be defined in the root directory and supports | ||
as many environments as you want. Simply use the `-e` flag and provide which environments you wish to | ||
use from the `.env-cmdrc` file. Using multiple environment names will merge the environment variables | ||
together. Later environments overwrite earlier ones in the list if conflicting environment variables | ||
are found. | ||
@@ -105,6 +86,6 @@ **.rc file `.env-cmdrc`** | ||
```sh | ||
./node_modules/.bin/env-cmd production node index.js | ||
./node_modules/.bin/env-cmd -e production node index.js | ||
# Or for multiple environments (where `production` vars override `test` vars, | ||
# but both are included) | ||
./node_modules/.bin/env-cmd test,production node index.js | ||
./node_modules/.bin/env-cmd -e test,production node index.js | ||
``` | ||
@@ -114,8 +95,37 @@ | ||
Sometimes you want to set env variables from a file without overriding existing process env vars or shell env vars. | ||
Prevents overriding of existing environment variables on `process.env` and within the current | ||
environment. | ||
### `--fallback` file usage option | ||
If the `.env` file does not exist at the provieded custom path, then use the default | ||
fallback location `./.env` env file instead. | ||
### `--use-shell` | ||
Executes the command within a new shell environment. This is useful if you want to string multiple | ||
commands together that share the same environment variables. | ||
**Terminal** | ||
```sh | ||
ENV1=welcome ./node_modules/.bin/env-cmd --no-override ./test/.env node index.js | ||
./node_modules/.bin/env-cmd -f ./test/.env --use-shell "node run lint && node test" | ||
``` | ||
### Asynchronous env file support | ||
EnvCmd supports reading from asynchronous `.env` files. Instead of using a `.env` file, pass in a `.js` | ||
file that returns a `Promise` resolving to an object (`{ ENV_VAR_NAME: value, ... }`). Asynchronous `.rc` | ||
files are also supported using `.js` file extension and resolving to an object with top level environment | ||
names (`{ production: { ENV_VAR_NAME: value, ... } }`). | ||
**Terminal** | ||
```sh | ||
./node_modules/.bin/env-cmd -f ./async-file.js node index.js | ||
``` | ||
## Examples | ||
You can find examples of how to use the various options above by visiting | ||
the examples repo [env-cmd-examples](https://github.com/toddbluhm/env-cmd-examples). | ||
## Environment File Formats | ||
@@ -126,3 +136,3 @@ | ||
- Key/value pairs as JSON | ||
- JavaScript file exporting an object | ||
- JavaScript file exporting an `object` or a `Promise` that resolves to an `object` | ||
- `.env-cmdrc` file (as valid json) in execution directory | ||
@@ -145,7 +155,37 @@ | ||
## ⚒ API Usage | ||
### `EnvCmd` | ||
A function that executes a given command in a new child process with the given environment and options | ||
- **`options`** { `object` } | ||
- **`command`** { `string` }: The command to execute (`node`, `mocha`, ...) | ||
- **`commandArgs`** { `string[]` }: List of arguments to pass to the `command` (`['-R', 'Spec']`) | ||
- **`envFile`** { `object` } | ||
- **`filePath`** { `string` }: Custom path to .env file to read from (defaults to: `./.env`) | ||
- **`fallback`** { `boolean` }: Should fall back to default `./.env` file if custom path does not exist | ||
- **`rc`** { `object` } | ||
- **`environments`** { `string[]` }: List of environment to read from the `.rc` file | ||
- **`filePath`** { `string` }: Custom path to the `.rc` file (defaults to: `./.env-cmdrc(|.js|.json)`) | ||
- **`options`** { `object` } | ||
- **`noOverride`** { `boolean` }: Prevent `.env` file vars from overriding existing `process.env` vars (default: `false`) | ||
- **`useShell`** { `boolean` }: Runs command inside a new shell instance (default: `false`) | ||
- **Returns** { `Promise<object>` }: key is env var name and value is the env var value | ||
### `GetEnvVars` | ||
A function that parses environment variables from a `.env` or a `.rc` file | ||
- **`options`** { `object` } | ||
- **`envFile`** { `object` } | ||
- **`filePath`** { `string` }: Custom path to .env file to read from (defaults to: `./.env`) | ||
- **`fallback`** { `boolean` }: Should fall back to default `./.env` file if custom path does not exist | ||
- **`rc`** { `object` } | ||
- **`environments`** { `string[]` }: List of environment to read from the `.rc` file | ||
- **`filePath`** { `string` }: Custom path to the `.rc` file (defaults to: `./.env-cmdrc(|.js|.json)`) | ||
- **Returns** { `Promise<object>` }: key is env var name and value is the env var value | ||
## Why | ||
Because sometimes its just too cumbersome passing lots of environment variables to scripts. Its usually just easier to have a file with all the vars in them, especially for development and testing. | ||
Because sometimes it is just too cumbersome passing a lot of environment variables to scripts. It is | ||
usually just easier to have a file with all the vars in them, especially for development and testing. | ||
**Do not commit sensitive environment data to a public git repo!** | ||
🚨**Do not commit sensitive environment data to a public git repo!** 🚨 | ||
@@ -156,7 +196,8 @@ ## Related Projects | ||
## Special Thanks | ||
## 🎊 Special Thanks | ||
Special thanks to [`cross-env`](https://github.com/kentcdodds/cross-env) for inspiration (use's the same `cross-spawn` lib underneath too). | ||
Special thanks to [`cross-env`](https://github.com/kentcdodds/cross-env) for inspiration (use's the | ||
same `cross-spawn` lib underneath too). | ||
## Contributors | ||
## 🎉 Contributors | ||
@@ -168,7 +209,8 @@ - Eric Lanehart | ||
## Contributing Guide | ||
I welcome all pull requests. Please make sure you add appropriate test cases for any features added. Before opening a PR please make sure to run the following scripts: | ||
## 📋 Contributing Guide | ||
I welcome all pull requests. Please make sure you add appropriate test cases for any features | ||
added. Before opening a PR please make sure to run the following scripts: | ||
- `npm run lint` checks for code errors and formats according to [js-standard](https://github.com/feross/standard) | ||
- `npm run lint` checks for code errors and format according to [js-standard](https://github.com/feross/standard) | ||
- `npm test` make sure all tests pass | ||
- `npm run test-cover` make sure the coverage has not decreased from current master |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
45646
27
619
209
2
20
6
+ Addedcommander@^2.20.0
+ Addedcommander@2.20.3(transitive)
Updatedcross-spawn@6.0.5