@dotenvx/dotenvx 0.32.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -260,6 +260,19 @@ More examples
|
|
|
260
260
|
see [platform guides](https://dotenvx.com/docs#platforms)
|
|
261
261
|
|
|
262
262
|
</details>
|
|
263
|
+
* <details><summary>Process Managers</summary><br>
|
|
264
|
+
|
|
265
|
+
```js
|
|
266
|
+
// pm2
|
|
267
|
+
"scripts": {
|
|
268
|
+
"start": "dotenvx run -- pm2-runtime start ecosystem.config.js --env production"
|
|
269
|
+
},
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
see [process manager guides](https://dotenvx.com/docs#process-managers)
|
|
273
|
+
|
|
274
|
+
</details>
|
|
275
|
+
|
|
263
276
|
* <details><summary>npx</summary><br>
|
|
264
277
|
|
|
265
278
|
```sh
|
|
@@ -354,12 +367,12 @@ More examples
|
|
|
354
367
|
|
|
355
368
|
## Multiple Environments
|
|
356
369
|
|
|
357
|
-
> Create a `.env.production` file and use
|
|
370
|
+
> Create a `.env.production` file and use `-f` to load it. It's straightforward, yet flexible.
|
|
358
371
|
```sh
|
|
359
372
|
$ echo "HELLO=production" > .env.production
|
|
360
373
|
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
361
374
|
|
|
362
|
-
$ dotenvx run
|
|
375
|
+
$ dotenvx run -f .env.production -- node index.js
|
|
363
376
|
[dotenvx][info] loading env (1) from .env.production
|
|
364
377
|
Hello production
|
|
365
378
|
> ^^
|
|
@@ -374,7 +387,7 @@ More examples
|
|
|
374
387
|
|
|
375
388
|
$ echo "HELLO=World" > .env
|
|
376
389
|
|
|
377
|
-
$ dotenvx run
|
|
390
|
+
$ dotenvx run -f .env.local -f .env -- node index.js
|
|
378
391
|
[dotenvx][info] loading env (1) from .env.local,.env
|
|
379
392
|
Hello local
|
|
380
393
|
```
|
|
@@ -388,7 +401,7 @@ More examples
|
|
|
388
401
|
|
|
389
402
|
$ echo "HELLO=World" > .env
|
|
390
403
|
|
|
391
|
-
$ dotenvx run
|
|
404
|
+
$ dotenvx run -f .env.local -f .env --overload -- node index.js
|
|
392
405
|
[dotenvx][info] loading env (1) from .env.local,.env
|
|
393
406
|
Hello World
|
|
394
407
|
```
|
|
@@ -398,7 +411,7 @@ More examples
|
|
|
398
411
|
```sh
|
|
399
412
|
$ echo "HELLO=production" > .env.production
|
|
400
413
|
|
|
401
|
-
$ dotenvx run
|
|
414
|
+
$ dotenvx run -f .env.production --verbose -- node index.js
|
|
402
415
|
[dotenvx][verbose] injecting env from /path/to/.env.production
|
|
403
416
|
[dotenvx][verbose] HELLO set
|
|
404
417
|
[dotenvx][info] loading env (1) from .env.production
|
|
@@ -410,7 +423,7 @@ More examples
|
|
|
410
423
|
```sh
|
|
411
424
|
$ echo "HELLO=production" > .env.production
|
|
412
425
|
|
|
413
|
-
$ dotenvx run
|
|
426
|
+
$ dotenvx run -f .env.production --debug -- node index.js
|
|
414
427
|
[dotenvx][debug] configuring options
|
|
415
428
|
[dotenvx][debug] {"envFile":[".env.production"]}
|
|
416
429
|
[dotenvx][verbose] injecting env from /path/to/.env.production
|
|
@@ -432,7 +445,7 @@ More examples
|
|
|
432
445
|
```sh
|
|
433
446
|
$ echo "HELLO=production" > .env.production
|
|
434
447
|
|
|
435
|
-
$ dotenvx run
|
|
448
|
+
$ dotenvx run -f .env.production --quiet -- node index.js
|
|
436
449
|
Hello production
|
|
437
450
|
```
|
|
438
451
|
|
|
@@ -444,7 +457,7 @@ More examples
|
|
|
444
457
|
```sh
|
|
445
458
|
$ echo "HELLO=production" > .env.production
|
|
446
459
|
|
|
447
|
-
$ dotenvx run
|
|
460
|
+
$ dotenvx run -f .env.production --log-level=error -- node index.js
|
|
448
461
|
Hello production
|
|
449
462
|
```
|
|
450
463
|
|
package/package.json
CHANGED
|
@@ -57,7 +57,8 @@ async function decrypt () {
|
|
|
57
57
|
const decrypted = libDecrypt(ciphertext, value.trim())
|
|
58
58
|
|
|
59
59
|
// envFilename
|
|
60
|
-
|
|
60
|
+
// replace _ with . to support filenames like .env.development.local
|
|
61
|
+
let envFilename = `.env.${environment.replace('_', '.')}`
|
|
61
62
|
if (environment === 'development') {
|
|
62
63
|
envFilename = '.env'
|
|
63
64
|
}
|
package/src/cli/dotenvx.js
CHANGED
|
@@ -12,7 +12,7 @@ const packageJson = require('./../lib/helpers/packageJson')
|
|
|
12
12
|
const notice = new UpdateNotice()
|
|
13
13
|
notice.check()
|
|
14
14
|
if (notice.update) {
|
|
15
|
-
logger.warn(`Update available ${notice.packageVersion} → ${notice.latestVersion}
|
|
15
|
+
logger.warn(`Update available ${notice.packageVersion} → ${notice.latestVersion} changelog: https://dotenvx.com/changelog`)
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
// for use with run
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
1
|
const crypto = require('crypto')
|
|
3
2
|
|
|
3
|
+
const guessEnvironment = require('./guessEnvironment')
|
|
4
|
+
|
|
4
5
|
class DotenvKeys {
|
|
5
6
|
constructor (envFilepaths = [], dotenvKeys = {}) {
|
|
6
7
|
this.envFilepaths = envFilepaths // pass .env* filepaths to be encrypted
|
|
@@ -12,7 +13,7 @@ class DotenvKeys {
|
|
|
12
13
|
const existingKeys = new Set()
|
|
13
14
|
|
|
14
15
|
for (const filepath of this.envFilepaths) {
|
|
15
|
-
const environment =
|
|
16
|
+
const environment = guessEnvironment(filepath)
|
|
16
17
|
const key = `DOTENV_KEY_${environment.toUpperCase()}`
|
|
17
18
|
|
|
18
19
|
let value = this.dotenvKeys[key]
|
|
@@ -46,18 +47,6 @@ class DotenvKeys {
|
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
_guessEnvironment (filepath) {
|
|
50
|
-
const filename = path.basename(filepath)
|
|
51
|
-
const parts = filename.split('.')
|
|
52
|
-
const possibleEnvironment = parts[2] // ['', 'env', environment', 'previous']
|
|
53
|
-
|
|
54
|
-
if (!possibleEnvironment || possibleEnvironment.length === 0) {
|
|
55
|
-
return 'development'
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return possibleEnvironment
|
|
59
|
-
}
|
|
60
|
-
|
|
61
50
|
_generateDotenvKey (environment) {
|
|
62
51
|
const rand = crypto.randomBytes(32).toString('hex')
|
|
63
52
|
|
|
@@ -3,13 +3,23 @@ const path = require('path')
|
|
|
3
3
|
function guessEnvironment (filepath) {
|
|
4
4
|
const filename = path.basename(filepath)
|
|
5
5
|
const parts = filename.split('.')
|
|
6
|
-
const
|
|
6
|
+
const possibleEnvironmentList = [...parts.slice(2)]
|
|
7
7
|
|
|
8
|
-
if (
|
|
8
|
+
if (possibleEnvironmentList.length === 0) {
|
|
9
9
|
return 'development'
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
if (possibleEnvironmentList.length === 1) {
|
|
13
|
+
return possibleEnvironmentList[0]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (
|
|
17
|
+
possibleEnvironmentList.length === 2
|
|
18
|
+
) {
|
|
19
|
+
return possibleEnvironmentList.join('_')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return possibleEnvironmentList.slice(0, 2).join('_')
|
|
13
23
|
}
|
|
14
24
|
|
|
15
25
|
module.exports = guessEnvironment
|