@dotenvx/dotenvx 0.10.4 → 0.10.6
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 +56 -1
- package/package.json +2 -2
- package/src/cli/actions/{predockerbuild.js → prebuild.js} +6 -6
- package/src/cli/dotenvx.js +5 -5
- package/src/cli/examples.js +5 -5
- package/src/lib/main.js +15 -1
- package/src/shared/logger.js +9 -9
package/README.md
CHANGED
|
@@ -11,10 +11,30 @@
|
|
|
11
11
|
|
|
12
12
|
### Quickstart
|
|
13
13
|
|
|
14
|
+
Install and use it in code just like `dotenv`.
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npm install @dotenvx/dotenvx --save
|
|
18
|
+
```
|
|
19
|
+
```js
|
|
20
|
+
// index.js
|
|
21
|
+
require('@dotenvx/dotenvx').config()
|
|
22
|
+
|
|
23
|
+
console.log(`Hello ${process.env.HELLO}`)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
Or install globally
|
|
29
|
+
|
|
14
30
|
```sh
|
|
15
31
|
brew install dotenvx/brew/dotenvx
|
|
16
32
|
```
|
|
17
|
-
> * [other ways to install](https://dotenvx.com/docs/install)
|
|
33
|
+
> * [other global ways to install](https://dotenvx.com/docs/install)
|
|
34
|
+
>
|
|
35
|
+
> Installing globally as a cli unlocks dotenv for ANY language, framework, or platform. 💥
|
|
36
|
+
>
|
|
37
|
+
> I am using (and recommending) this approach going forward. – [motdotla](https://github.com/motdotla)
|
|
18
38
|
|
|
19
39
|
|
|
20
40
|
|
|
@@ -134,6 +154,14 @@ More examples
|
|
|
134
154
|
World
|
|
135
155
|
```
|
|
136
156
|
|
|
157
|
+
</details>
|
|
158
|
+
* <details><summary>Cron ⏰</summary><br>
|
|
159
|
+
|
|
160
|
+
```sh
|
|
161
|
+
# run every day at 8am
|
|
162
|
+
0 8 * * * dotenvx run -- /path/to/myscript.sh
|
|
163
|
+
```
|
|
164
|
+
|
|
137
165
|
</details>
|
|
138
166
|
* <details><summary>Frameworks ▲</summary><br>
|
|
139
167
|
|
|
@@ -329,6 +357,33 @@ More examples
|
|
|
329
357
|
```
|
|
330
358
|
|
|
331
359
|
</details>
|
|
360
|
+
* <details><summary>`--quiet` flag</summary><br>
|
|
361
|
+
|
|
362
|
+
Use `--quiet` to suppress all output (except errors).
|
|
363
|
+
|
|
364
|
+
```sh
|
|
365
|
+
$ echo "HELLO=production" > .env.production
|
|
366
|
+
|
|
367
|
+
$ dotenvx run --env-file=.env.production --quiet -- node index.js
|
|
368
|
+
Hello production
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
</details>
|
|
372
|
+
* <details><summary>`--log-level` flag</summary><br>
|
|
373
|
+
|
|
374
|
+
Set `--log-level` to whatever you wish. For example, to supress warnings (risky), set log level to `error`:
|
|
375
|
+
|
|
376
|
+
```sh
|
|
377
|
+
$ echo "HELLO=production" > .env.production
|
|
378
|
+
|
|
379
|
+
$ dotenvx run --env-file=.env.production --log-level=error -- node index.js
|
|
380
|
+
Hello production
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
Available log levels are `error, warn, info, verbose, debug, silly`
|
|
384
|
+
|
|
385
|
+
</details>
|
|
386
|
+
|
|
332
387
|
|
|
333
388
|
|
|
334
389
|
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.10.
|
|
2
|
+
"version": "0.10.6",
|
|
3
3
|
"name": "@dotenvx/dotenvx",
|
|
4
4
|
"description": "a better dotenv–from the creator of `dotenv`",
|
|
5
5
|
"author": "@motdotla",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"clipboardy": "^2.3.0",
|
|
31
31
|
"commander": "^11.1.0",
|
|
32
32
|
"conf": "^10.2.0",
|
|
33
|
-
"dotenv": "^16.
|
|
33
|
+
"dotenv": "^16.4.0",
|
|
34
34
|
"execa": "^5.1.1",
|
|
35
35
|
"ignore": "^5.3.0",
|
|
36
36
|
"open": "^8.4.2",
|
|
@@ -5,13 +5,13 @@ const ignore = require('ignore')
|
|
|
5
5
|
const logger = require('./../../shared/logger')
|
|
6
6
|
const helpers = require('./../helpers')
|
|
7
7
|
|
|
8
|
-
function
|
|
8
|
+
function prebuild () {
|
|
9
9
|
const options = this.opts()
|
|
10
10
|
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
11
11
|
|
|
12
12
|
// 1. check for .dockerignore file
|
|
13
13
|
if (!fs.existsSync('.dockerignore')) {
|
|
14
|
-
logger.
|
|
14
|
+
logger.errorvpb('.dockerignore missing')
|
|
15
15
|
logger.help2('? add it with [touch .dockerignore]')
|
|
16
16
|
process.exit(1)
|
|
17
17
|
}
|
|
@@ -45,7 +45,7 @@ function predockerbuild () {
|
|
|
45
45
|
case '.env.vault':
|
|
46
46
|
break
|
|
47
47
|
default:
|
|
48
|
-
logger.
|
|
48
|
+
logger.errorvpb(`${file} not properly dockerignored`)
|
|
49
49
|
logger.help2(`? add ${file} to .dockerignore with [echo ".env*" >> .dockerignore]`)
|
|
50
50
|
process.exit(1) // 3.1 exit early with error code
|
|
51
51
|
break
|
|
@@ -55,10 +55,10 @@ function predockerbuild () {
|
|
|
55
55
|
|
|
56
56
|
// 3. outpout success
|
|
57
57
|
if (warningCount > 0) {
|
|
58
|
-
logger.
|
|
58
|
+
logger.successvpb(`success (with ${helpers.pluralize('warning', warningCount)})`)
|
|
59
59
|
} else {
|
|
60
|
-
logger.
|
|
60
|
+
logger.successvpb('success')
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
module.exports =
|
|
64
|
+
module.exports = prebuild
|
package/src/cli/dotenvx.js
CHANGED
|
@@ -73,11 +73,11 @@ program.command('precommit')
|
|
|
73
73
|
.option('-i, --install', 'install to .git/hooks/pre-commit')
|
|
74
74
|
.action(require('./actions/precommit'))
|
|
75
75
|
|
|
76
|
-
// dotenvx
|
|
77
|
-
program.command('
|
|
78
|
-
.description('prevent including .env files in docker
|
|
79
|
-
.addHelpText('after', examples.
|
|
80
|
-
.action(require('./actions/
|
|
76
|
+
// dotenvx prebuild
|
|
77
|
+
program.command('prebuild')
|
|
78
|
+
.description('prevent including .env files in docker builds')
|
|
79
|
+
.addHelpText('after', examples.prebuild)
|
|
80
|
+
.action(require('./actions/prebuild'))
|
|
81
81
|
|
|
82
82
|
// dotenvx hub
|
|
83
83
|
program.addCommand(require('./commands/hub'))
|
package/src/cli/examples.js
CHANGED
|
@@ -66,19 +66,19 @@ Try it:
|
|
|
66
66
|
`
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
const
|
|
69
|
+
const prebuild = function () {
|
|
70
70
|
return `
|
|
71
71
|
Examples:
|
|
72
72
|
|
|
73
73
|
\`\`\`
|
|
74
|
-
$ dotenvx
|
|
74
|
+
$ dotenvx prebuild
|
|
75
75
|
\`\`\`
|
|
76
76
|
|
|
77
77
|
Try it:
|
|
78
78
|
|
|
79
79
|
\`\`\`
|
|
80
|
-
$ dotenvx
|
|
81
|
-
[dotenvx@0.10.0][
|
|
80
|
+
$ dotenvx prebuild
|
|
81
|
+
[dotenvx@0.10.0][prebuild] success
|
|
82
82
|
\`\`\`
|
|
83
83
|
`
|
|
84
84
|
}
|
|
@@ -87,5 +87,5 @@ module.exports = {
|
|
|
87
87
|
run,
|
|
88
88
|
encrypt,
|
|
89
89
|
precommit,
|
|
90
|
-
|
|
90
|
+
prebuild
|
|
91
91
|
}
|
package/src/lib/main.js
CHANGED
|
@@ -6,7 +6,21 @@ const config = function (options) {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
const decrypt = function (encrypted, keyStr) {
|
|
9
|
-
|
|
9
|
+
try {
|
|
10
|
+
return dotenv.decrypt(encrypted, keyStr)
|
|
11
|
+
} catch (e) {
|
|
12
|
+
switch (e.code) {
|
|
13
|
+
case 'DECRYPTION_FAILED':
|
|
14
|
+
// more helpful error when decryption fails
|
|
15
|
+
logger.error('[DECRYPTION_FAILED] Unable to decrypt .env.vault with DOTENV_KEY.')
|
|
16
|
+
logger.help('[DECRYPTION_FAILED] Run with debug flag [dotenvx run --debug -- yourcommand] or manually run [echo $DOTENV_KEY] to compare it to the one in .env.keys.')
|
|
17
|
+
logger.debug(`[DECRYPTION_FAILED] DOTENV_KEY is ${process.env.DOTENV_KEY}`)
|
|
18
|
+
process.exit(1)
|
|
19
|
+
break
|
|
20
|
+
default:
|
|
21
|
+
throw e
|
|
22
|
+
}
|
|
23
|
+
}
|
|
10
24
|
}
|
|
11
25
|
|
|
12
26
|
const configDotenv = function (options) {
|
package/src/shared/logger.js
CHANGED
|
@@ -12,15 +12,15 @@ const levels = {
|
|
|
12
12
|
error: 0,
|
|
13
13
|
errorv: 0,
|
|
14
14
|
errorvp: 0,
|
|
15
|
-
|
|
15
|
+
errorvpb: 0,
|
|
16
16
|
warn: 1,
|
|
17
17
|
warnv: 1,
|
|
18
18
|
warnvp: 1,
|
|
19
|
-
|
|
19
|
+
warnvpb: 1,
|
|
20
20
|
success: 2,
|
|
21
21
|
successv: 2,
|
|
22
22
|
successvp: 2,
|
|
23
|
-
|
|
23
|
+
successvpb: 2,
|
|
24
24
|
info: 2,
|
|
25
25
|
help: 2,
|
|
26
26
|
help2: 2,
|
|
@@ -51,24 +51,24 @@ const dotenvxFormat = printf(({ level, message, label, timestamp }) => {
|
|
|
51
51
|
return error(`[dotenvx@${packageJson.version}] ${formattedMessage}`)
|
|
52
52
|
case 'errorvp':
|
|
53
53
|
return error(`[dotenvx@${packageJson.version}][precommit] ${formattedMessage}`)
|
|
54
|
-
case '
|
|
55
|
-
return error(`[dotenvx@${packageJson.version}][
|
|
54
|
+
case 'errorvpb':
|
|
55
|
+
return error(`[dotenvx@${packageJson.version}][prebuild] ${formattedMessage}`)
|
|
56
56
|
case 'warn':
|
|
57
57
|
return warn(formattedMessage)
|
|
58
58
|
case 'warnv':
|
|
59
59
|
return warn(`[dotenvx@${packageJson.version}] ${formattedMessage}`)
|
|
60
60
|
case 'warnvp':
|
|
61
61
|
return warn(`[dotenvx@${packageJson.version}][precommit] ${formattedMessage}`)
|
|
62
|
-
case '
|
|
63
|
-
return warn(`[dotenvx@${packageJson.version}][
|
|
62
|
+
case 'warnvpb':
|
|
63
|
+
return warn(`[dotenvx@${packageJson.version}][prebuild] ${formattedMessage}`)
|
|
64
64
|
case 'success':
|
|
65
65
|
return success(formattedMessage)
|
|
66
66
|
case 'successv': // success with 'version'
|
|
67
67
|
return successv(`[dotenvx@${packageJson.version}] ${formattedMessage}`)
|
|
68
68
|
case 'successvp': // success with 'version' and precommit
|
|
69
69
|
return success(`[dotenvx@${packageJson.version}][precommit] ${formattedMessage}`)
|
|
70
|
-
case '
|
|
71
|
-
return success(`[dotenvx@${packageJson.version}][
|
|
70
|
+
case 'successvpb': // success with 'version' and precommit
|
|
71
|
+
return success(`[dotenvx@${packageJson.version}][prebuild] ${formattedMessage}`)
|
|
72
72
|
case 'info':
|
|
73
73
|
return formattedMessage
|
|
74
74
|
case 'help':
|