Skip to content

Commit

Permalink
Merge branch 'release/2.8.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
keithmorris committed Mar 25, 2020
2 parents 37128eb + e8e9e0a commit 5b2a933
Show file tree
Hide file tree
Showing 15 changed files with 3,326 additions and 1,092 deletions.
8 changes: 3 additions & 5 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"presets": [
"env"
"@babel/preset-env"
],
"plugins": [
"transform-object-rest-spread"
]
}
"plugins": []
}
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ test
.eslintrc
.gitignore
.travis.yml
gulpfile.js
gulpfile.esm.js
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: node_js
node_js:
- "12"
- "10"
- "8"
- "6"
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 2.8.0 - 2020.03.25
- Update dependencies while retaining compatibility with Node 6
- Add ability to configure through environment variables (thanks @Levino)
- Remove `@types/dotenv` as a dependency
- Add Node 12 to travis-ci tests
- General code cleanup/modernizing

## 2.7.1 - 2019.12.30
- Update README to include `import` syntax

Expand Down
62 changes: 40 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ I have tried to stay as compatible as possible with the [dotenv] library but the

## Installation

```
```bash
npm i --save dotenv-extended
```

## Usage

As early as possible in your main script:

```
```javascript
require('dotenv-extended').load();
```

Or if you prefer import syntax:

```
```javascript
import dotEnvExtended from 'dotenv-extended';
dotEnvExtended.load();
```
Expand Down Expand Up @@ -87,13 +87,14 @@ mongoose.connect('mongodb://' + process.env.MONGO_HOST + '/' + process.env.MONGO
### Load Configs from command line

You may also load the `.env` files from the command line. Add in the require `dotenv-extended/config` along with any of the options that the `load` method takes prefixed with `dotenv_config_`. e.g.:
```

```bash
node -r dotenv-extended/config your_script.js
```

Or to specify load options:

```
```bash
node -r dotenv-extended/config your_script.js dotenv_config_path=./env/.env dotenv_config_defaults=./env/.env.defaults
```

Expand All @@ -103,19 +104,19 @@ New in 2.0.0, is a feature inspired by [cross-env](https://www.npmjs.com/package

Install Globally:

```
```bash
npm install -g dotenv-extended
```

Now call your shell scripts through `dotenv-extended` (this uses the defaults):

```
```bash
dotenv-extended ./myshellscript.sh --whatever-flags-my-script-takes
```

Configure `dotenv-extended` by passing any of the dotenv-extended options before your command. Preceed each option with two dashes `--`:

```
```bash
dotenv-extended --path=/path/to/.env --defaults=/path/to/.env.defaults --errorOnMissing=true ./myshellscript.sh --whatever-flags-my-script-takes
```

Expand All @@ -139,7 +140,7 @@ The following are the flags you can pass to the `dotenv-extended` cli with their

Defaults are shown below:

```
```javascript
require('dotenv-extended').load({
encoding: 'utf8',
silent: true,
Expand All @@ -154,11 +155,28 @@ require('dotenv-extended').load({
overrideProcessEnv: false
});
```
### Configure via Environment Variables (New in 2.8.0)

The function always returns an object containing the variables loaded from the `.env` and `.env.defaults` files. The returned object does not contain the properties held in `process.env` but rather only the ones that are loaded from the `.env` and `.env.defaults` files.
You may also set the configuration values via environment variables loaded from `process.env` shown below with defaults:

```
var myConfig = require('dotenv-extended').load();
DOTENV_CONFIG_ENCODING=utf8
DOTENV_CONFIG_SILENT=true
DOTENV_CONFIG_PATH=.env
DOTENV_CONFIG_DEFAULTS=.env.defaults
DOTENV_CONFIG_SCHEMA=.env.schema
DOTENV_CONFIG_ERROR_ON_MISSING=false
DOTENV_CONFIG_ERROR_ON_EXTRA=false
DOTENV_CONFIG_ERROR_ON_REGEX=false
DOTENV_CONFIG_INCLUDE_PROCESS_ENV=false
DOTENV_CONFIG_ASSIGN_TO_PROCESS_ENV=true
DOTENV_CONFIG_OVERRIDE_PROCESS_ENV=false
```

The `load()` function always returns an object containing the variables loaded from the `.env` and `.env.defaults` files. By default the returned object does not contain the properties held in `process.env` but rather only the ones that are loaded from the `.env` and `.env.defaults` files.

```javascript
const myConfig = require('dotenv-extended').load();
```

### encoding (_default: utf8_)
Expand Down Expand Up @@ -234,8 +252,8 @@ API_KEY=

### Load files with default options

```
var myConfig = require('dotenv-extended').load();
```javascript
const myConfig = require('dotenv-extended').load();

myConfig.DB_HOST === process.env.DB_HOST === "localhost"
myConfig.DB_USER === process.env.DB_USER === "databaseuser-local"
Expand All @@ -246,32 +264,32 @@ myConfig.SHARE_URL === process.env.SHARE_URL === "http://www.example.com"

### Load files with `errorOnMissing`

```
var myConfig = require('dotenv-extended').load({
```javascript
const myConfig = require('dotenv-extended').load({
errorOnMissing: true
});

Throws ERROR `MISSING CONFIG VALUES: API_KEY`
// Throws ERROR `MISSING CONFIG VALUES: API_KEY`
```

### Load files with `errorOnExtra`

```
var myConfig = require('dotenv-extended').load({
```javascript
const myConfig = require('dotenv-extended').load({
errorOnExtra: true
});

Throws ERROR `EXTRA CONFIG VALUES: SHARE_URL`
// Throws ERROR `EXTRA CONFIG VALUES: SHARE_URL`
```

### Load files with `errorOnRegex`

```
var myConfig = require('dotenv-extended').load({
```javascript
const myConfig = require('dotenv-extended').load({
errorOnRegex: true
});

Throws ERROR `REGEX MISMATCH: DB_USER`
// Throws ERROR `REGEX MISMATCH: DB_USER`
```

## Contributing
Expand Down
35 changes: 35 additions & 0 deletions gulpfile.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Created by Keith Morris on 2/9/16.
*/
import babel from 'gulp-babel';
import del from 'del';
import eslint from 'gulp-eslint';
import { src, dest, series, watch } from 'gulp';

const options = {
buildDir: 'lib'
};

export const clean = () => del([
options.buildDir,
'coverage',
'.nyc_output'
]);

const watchFiles = () => {
watch(['src/**/*.js'], series([build]));
};
export { watchFiles as watch };

export const lint = () => src(['src/**/*.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());

export const scripts = () => src(['src/**/*.js'])
.pipe(babel())
.pipe(dest(options.buildDir));

export const build = series([clean, lint, scripts]);

export default build;
42 changes: 0 additions & 42 deletions gulpfile.js

This file was deleted.

Loading

0 comments on commit 5b2a933

Please sign in to comment.