Skip to content

Commit 5b2a933

Browse files
committed
Merge branch 'release/2.8.0'
2 parents 37128eb + e8e9e0a commit 5b2a933

File tree

15 files changed

+3326
-1092
lines changed

15 files changed

+3326
-1092
lines changed

.babelrc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
22
"presets": [
3-
"env"
3+
"@babel/preset-env"
44
],
5-
"plugins": [
6-
"transform-object-rest-spread"
7-
]
8-
}
5+
"plugins": []
6+
}

.npmignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ test
77
.eslintrc
88
.gitignore
99
.travis.yml
10-
gulpfile.js
10+
gulpfile.esm.js

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: node_js
22
node_js:
3+
- "12"
34
- "10"
45
- "8"
56
- "6"

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 2.8.0 - 2020.03.25
4+
- Update dependencies while retaining compatibility with Node 6
5+
- Add ability to configure through environment variables (thanks @Levino)
6+
- Remove `@types/dotenv` as a dependency
7+
- Add Node 12 to travis-ci tests
8+
- General code cleanup/modernizing
9+
310
## 2.7.1 - 2019.12.30
411
- Update README to include `import` syntax
512

README.md

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,21 @@ I have tried to stay as compatible as possible with the [dotenv] library but the
4545

4646
## Installation
4747

48-
```
48+
```bash
4949
npm i --save dotenv-extended
5050
```
5151

5252
## Usage
5353

5454
As early as possible in your main script:
5555

56-
```
56+
```javascript
5757
require('dotenv-extended').load();
5858
```
5959

6060
Or if you prefer import syntax:
6161

62-
```
62+
```javascript
6363
import dotEnvExtended from 'dotenv-extended';
6464
dotEnvExtended.load();
6565
```
@@ -87,13 +87,14 @@ mongoose.connect('mongodb://' + process.env.MONGO_HOST + '/' + process.env.MONGO
8787
### Load Configs from command line
8888

8989
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.:
90-
```
90+
91+
```bash
9192
node -r dotenv-extended/config your_script.js
9293
```
9394

9495
Or to specify load options:
9596

96-
```
97+
```bash
9798
node -r dotenv-extended/config your_script.js dotenv_config_path=./env/.env dotenv_config_defaults=./env/.env.defaults
9899
```
99100

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

104105
Install Globally:
105106

106-
```
107+
```bash
107108
npm install -g dotenv-extended
108109
```
109110

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

112-
```
113+
```bash
113114
dotenv-extended ./myshellscript.sh --whatever-flags-my-script-takes
114115
```
115116

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

118-
```
119+
```bash
119120
dotenv-extended --path=/path/to/.env --defaults=/path/to/.env.defaults --errorOnMissing=true ./myshellscript.sh --whatever-flags-my-script-takes
120121
```
121122

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

140141
Defaults are shown below:
141142

142-
```
143+
```javascript
143144
require('dotenv-extended').load({
144145
encoding: 'utf8',
145146
silent: true,
@@ -154,11 +155,28 @@ require('dotenv-extended').load({
154155
overrideProcessEnv: false
155156
});
156157
```
158+
### Configure via Environment Variables (New in 2.8.0)
157159

158-
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.
160+
You may also set the configuration values via environment variables loaded from `process.env` shown below with defaults:
159161

160162
```
161-
var myConfig = require('dotenv-extended').load();
163+
DOTENV_CONFIG_ENCODING=utf8
164+
DOTENV_CONFIG_SILENT=true
165+
DOTENV_CONFIG_PATH=.env
166+
DOTENV_CONFIG_DEFAULTS=.env.defaults
167+
DOTENV_CONFIG_SCHEMA=.env.schema
168+
DOTENV_CONFIG_ERROR_ON_MISSING=false
169+
DOTENV_CONFIG_ERROR_ON_EXTRA=false
170+
DOTENV_CONFIG_ERROR_ON_REGEX=false
171+
DOTENV_CONFIG_INCLUDE_PROCESS_ENV=false
172+
DOTENV_CONFIG_ASSIGN_TO_PROCESS_ENV=true
173+
DOTENV_CONFIG_OVERRIDE_PROCESS_ENV=false
174+
```
175+
176+
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.
177+
178+
```javascript
179+
const myConfig = require('dotenv-extended').load();
162180
```
163181

164182
### encoding (_default: utf8_)
@@ -234,8 +252,8 @@ API_KEY=
234252

235253
### Load files with default options
236254

237-
```
238-
var myConfig = require('dotenv-extended').load();
255+
```javascript
256+
const myConfig = require('dotenv-extended').load();
239257

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

247265
### Load files with `errorOnMissing`
248266

249-
```
250-
var myConfig = require('dotenv-extended').load({
267+
```javascript
268+
const myConfig = require('dotenv-extended').load({
251269
errorOnMissing: true
252270
});
253271

254-
Throws ERROR `MISSING CONFIG VALUES: API_KEY`
272+
// Throws ERROR `MISSING CONFIG VALUES: API_KEY`
255273
```
256274

257275
### Load files with `errorOnExtra`
258276

259-
```
260-
var myConfig = require('dotenv-extended').load({
277+
```javascript
278+
const myConfig = require('dotenv-extended').load({
261279
errorOnExtra: true
262280
});
263281

264-
Throws ERROR `EXTRA CONFIG VALUES: SHARE_URL`
282+
// Throws ERROR `EXTRA CONFIG VALUES: SHARE_URL`
265283
```
266284

267285
### Load files with `errorOnRegex`
268286

269-
```
270-
var myConfig = require('dotenv-extended').load({
287+
```javascript
288+
const myConfig = require('dotenv-extended').load({
271289
errorOnRegex: true
272290
});
273291

274-
Throws ERROR `REGEX MISMATCH: DB_USER`
292+
// Throws ERROR `REGEX MISMATCH: DB_USER`
275293
```
276294

277295
## Contributing

gulpfile.esm.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Created by Keith Morris on 2/9/16.
3+
*/
4+
import babel from 'gulp-babel';
5+
import del from 'del';
6+
import eslint from 'gulp-eslint';
7+
import { src, dest, series, watch } from 'gulp';
8+
9+
const options = {
10+
buildDir: 'lib'
11+
};
12+
13+
export const clean = () => del([
14+
options.buildDir,
15+
'coverage',
16+
'.nyc_output'
17+
]);
18+
19+
const watchFiles = () => {
20+
watch(['src/**/*.js'], series([build]));
21+
};
22+
export { watchFiles as watch };
23+
24+
export const lint = () => src(['src/**/*.js'])
25+
.pipe(eslint())
26+
.pipe(eslint.format())
27+
.pipe(eslint.failAfterError());
28+
29+
export const scripts = () => src(['src/**/*.js'])
30+
.pipe(babel())
31+
.pipe(dest(options.buildDir));
32+
33+
export const build = series([clean, lint, scripts]);
34+
35+
export default build;

gulpfile.js

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)