@dotenvx/dotenvx 0.10.2 → 0.10.4
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 +108 -9
- package/package.json +1 -1
- package/src/cli/actions/precommit.js +11 -1
- package/src/cli/actions/predockerbuild.js +64 -0
- package/src/cli/actions/run.js +1 -0
- package/src/cli/dotenvx.js +7 -1
- package/src/cli/examples.js +19 -1
- package/src/shared/logger.js +9 -0
package/README.md
CHANGED
|
@@ -32,6 +32,8 @@ Hello World
|
|
|
32
32
|
> :-D
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
see [extended quickstart guide](https://dotenvx.com/docs/quickstart)
|
|
36
|
+
|
|
35
37
|
More examples
|
|
36
38
|
|
|
37
39
|
* <details><summary>Python 🐍</summary><br>
|
|
@@ -44,6 +46,8 @@ More examples
|
|
|
44
46
|
Hello World
|
|
45
47
|
```
|
|
46
48
|
|
|
49
|
+
see [extended python guide](https://dotenvx.com/docs/quickstart)
|
|
50
|
+
|
|
47
51
|
</details>
|
|
48
52
|
* <details><summary>PHP 🐘</summary><br>
|
|
49
53
|
|
|
@@ -55,6 +59,8 @@ More examples
|
|
|
55
59
|
Hello World
|
|
56
60
|
```
|
|
57
61
|
|
|
62
|
+
see [extended php guide](https://dotenvx.com/docs/quickstart)
|
|
63
|
+
|
|
58
64
|
</details>
|
|
59
65
|
* <details><summary>Ruby 💎</summary><br>
|
|
60
66
|
|
|
@@ -66,6 +72,8 @@ More examples
|
|
|
66
72
|
Hello World
|
|
67
73
|
```
|
|
68
74
|
|
|
75
|
+
see [extended ruby guide](https://dotenvx.com/docs/quickstart)
|
|
76
|
+
|
|
69
77
|
</details>
|
|
70
78
|
* <details><summary>Go 🐹</summary><br>
|
|
71
79
|
|
|
@@ -77,6 +85,8 @@ More examples
|
|
|
77
85
|
Hello World
|
|
78
86
|
```
|
|
79
87
|
|
|
88
|
+
see [extended go guide](https://dotenvx.com/docs/quickstart)
|
|
89
|
+
|
|
80
90
|
</details>
|
|
81
91
|
* <details><summary>Rust 🦀</summary><br>
|
|
82
92
|
|
|
@@ -88,6 +98,8 @@ More examples
|
|
|
88
98
|
Hello World
|
|
89
99
|
```
|
|
90
100
|
|
|
101
|
+
see [extended rust guide](https://dotenvx.com/docs/quickstart)
|
|
102
|
+
|
|
91
103
|
</details>
|
|
92
104
|
* <details><summary>Java ☕️</summary><br>
|
|
93
105
|
|
|
@@ -132,6 +144,8 @@ More examples
|
|
|
132
144
|
$ dotenvx run -- php artisan serve
|
|
133
145
|
```
|
|
134
146
|
|
|
147
|
+
see [framework guides](https://dotenvx.com/docs#frameworks)
|
|
148
|
+
|
|
135
149
|
</details>
|
|
136
150
|
* <details><summary>Docker 🐳</summary><br>
|
|
137
151
|
|
|
@@ -148,21 +162,47 @@ More examples
|
|
|
148
162
|
CMD ["dotenvx", "run", "--", "echo", "Hello $HELLO"]
|
|
149
163
|
```
|
|
150
164
|
|
|
165
|
+
see [docker guide](https://dotenvx.com/docs/platforms/docker)
|
|
166
|
+
|
|
151
167
|
</details>
|
|
152
168
|
|
|
153
169
|
* <details><summary>CI/CDs 🐙</summary><br>
|
|
154
170
|
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
|
|
171
|
+
```yaml
|
|
172
|
+
name: build
|
|
173
|
+
on: [push]
|
|
174
|
+
jobs:
|
|
175
|
+
build:
|
|
176
|
+
runs-on: ubuntu-latest
|
|
177
|
+
steps:
|
|
178
|
+
- uses: actions/checkout@v3
|
|
179
|
+
- uses: actions/setup-node@v3
|
|
180
|
+
with:
|
|
181
|
+
node-version: 16
|
|
182
|
+
- run: curl -fsS https://dotenvx.sh/ | sh
|
|
183
|
+
- run: dotenvx run -- node build.js
|
|
184
|
+
env:
|
|
185
|
+
DOTENV_KEY: ${{ secrets.DOTENV_KEY }}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
see [github actions guide](https://dotenvx.com/docs/cis/github-actions)
|
|
158
189
|
|
|
159
190
|
</details>
|
|
160
191
|
* <details><summary>Platforms</summary><br>
|
|
161
192
|
|
|
162
193
|
```sh
|
|
163
|
-
|
|
194
|
+
# heroku
|
|
195
|
+
heroku buildpacks:add https://github.com/dotenvx/heroku-buildpack-dotenvx
|
|
196
|
+
|
|
197
|
+
# docker
|
|
198
|
+
RUN curl -fsS https://dotenvx.sh/ | sh
|
|
199
|
+
|
|
200
|
+
# vercel
|
|
201
|
+
npm install @dotenvx/dotenvx --save
|
|
164
202
|
```
|
|
165
203
|
|
|
204
|
+
see [platform guides](https://dotenvx.com/docs#platforms)
|
|
205
|
+
|
|
166
206
|
</details>
|
|
167
207
|
* <details><summary>npx</summary><br>
|
|
168
208
|
|
|
@@ -330,12 +370,23 @@ More examples
|
|
|
330
370
|
|
|
331
371
|
* <details><summary>Docker</summary><br>
|
|
332
372
|
|
|
373
|
+
> Add the `dotenvx` binary to your Dockerfile
|
|
374
|
+
|
|
333
375
|
```sh
|
|
334
|
-
|
|
376
|
+
# Install dotenvx
|
|
377
|
+
RUN curl -fsS https://dotenvx.sh/ | sh
|
|
335
378
|
```
|
|
336
379
|
|
|
337
|
-
|
|
380
|
+
> Use it in your Dockerfile CMD
|
|
338
381
|
|
|
382
|
+
```sh
|
|
383
|
+
# Prepend dotenvx run
|
|
384
|
+
CMD ["dotenvx", "run", "--", "node", "index.js"]
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
see [docker guide](https://dotenvx.com/docs/platforms/docker)
|
|
388
|
+
|
|
389
|
+
</details>
|
|
339
390
|
|
|
340
391
|
* <details><summary>Fly.io</summary><br>
|
|
341
392
|
|
|
@@ -359,7 +410,7 @@ More examples
|
|
|
359
410
|
web: dotenvx run -- node index.js
|
|
360
411
|
```
|
|
361
412
|
|
|
362
|
-
|
|
413
|
+
see [heroku guide](https://dotenvx.com/docs/platforms/heroku)
|
|
363
414
|
|
|
364
415
|
</details>
|
|
365
416
|
|
|
@@ -397,10 +448,25 @@ More examples
|
|
|
397
448
|
|
|
398
449
|
* <details><summary>Vercel</summary><br>
|
|
399
450
|
|
|
451
|
+
> Add the `dotenvx` npm module
|
|
452
|
+
|
|
400
453
|
```sh
|
|
401
|
-
|
|
454
|
+
npm install @dotenvx/dotenvx --save
|
|
402
455
|
```
|
|
403
456
|
|
|
457
|
+
> Use it in your `package.json scripts`
|
|
458
|
+
|
|
459
|
+
```json
|
|
460
|
+
"scripts": {
|
|
461
|
+
"dotenvx": "dotenvx",
|
|
462
|
+
"dev": "dotenvx run -- next dev --turbo",
|
|
463
|
+
"build": "dotenvx run -- next build",
|
|
464
|
+
"start": "dotenvx run -- next start"
|
|
465
|
+
},
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
see [vercel guide](https://dotenvx.com/docs/platforms/vercel)
|
|
469
|
+
|
|
404
470
|
</details>
|
|
405
471
|
|
|
406
472
|
* <details><summary>CircleCI</summary><br>
|
|
@@ -413,19 +479,50 @@ More examples
|
|
|
413
479
|
|
|
414
480
|
* <details><summary>GitHub Actions</summary><br>
|
|
415
481
|
|
|
482
|
+
> Add the `dotenvx` binary to GitHub Actions
|
|
483
|
+
|
|
416
484
|
```sh
|
|
417
|
-
|
|
485
|
+
name: build
|
|
486
|
+
on: [push]
|
|
487
|
+
jobs:
|
|
488
|
+
build:
|
|
489
|
+
runs-on: ubuntu-latest
|
|
490
|
+
steps:
|
|
491
|
+
- uses: actions/checkout@v3
|
|
492
|
+
- uses: actions/setup-node@v3
|
|
493
|
+
with:
|
|
494
|
+
node-version: 16
|
|
495
|
+
- run: curl -fsS https://dotenvx.sh/ | sh
|
|
496
|
+
- run: dotenvx run -- node build.js
|
|
497
|
+
env:
|
|
498
|
+
DOTENV_KEY: ${{ secrets.DOTENV_KEY }}
|
|
418
499
|
```
|
|
419
500
|
|
|
501
|
+
see [github actions guide](https://dotenvx.com/docs/cis/github-actions)
|
|
502
|
+
|
|
420
503
|
</details>
|
|
421
504
|
|
|
422
505
|
|
|
423
506
|
|
|
507
|
+
## Hub
|
|
508
|
+
|
|
509
|
+
> Integrate tightly with [GitHub](https://github.com) 🐙
|
|
510
|
+
```sh
|
|
511
|
+
$ dotenvx hub login
|
|
512
|
+
$ dotenvx hub push
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
more details coming soon.
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
|
|
424
519
|
## Guides
|
|
425
520
|
|
|
426
521
|
* [dotenvx/docs](https://dotenvx.com/docs)
|
|
427
522
|
* [quickstart guide](https://dotenvx.com/docs/quickstart)
|
|
428
523
|
|
|
524
|
+
|
|
525
|
+
|
|
429
526
|
## Pre-commit
|
|
430
527
|
|
|
431
528
|
You can prevent `.env` files from being committed to code with this pre-commit hook.
|
|
@@ -446,6 +543,8 @@ To ignore the pre-commit hook run your git commit with the `--no-verify` flag.
|
|
|
446
543
|
git commit -am "msg" --no-verify
|
|
447
544
|
```
|
|
448
545
|
|
|
546
|
+
|
|
547
|
+
|
|
449
548
|
## Contributing
|
|
450
549
|
|
|
451
550
|
You can fork this repo and create [pull requests](https://github.com/dotenvx/dotenvx/pulls) or if you have questions or feedback:
|
package/package.json
CHANGED
|
@@ -69,7 +69,17 @@ function precommit () {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
function installPrecommitHook () {
|
|
72
|
-
const hookScript =
|
|
72
|
+
const hookScript = `#!/bin/sh
|
|
73
|
+
|
|
74
|
+
if ! command -v dotenvx &> /dev/null
|
|
75
|
+
then
|
|
76
|
+
echo "[dotenvx][precommit] 'dotenvx' command not found"
|
|
77
|
+
echo "[dotenvx][precommit] ? install it with [brew install dotenvx/brew/dotenvx]"
|
|
78
|
+
echo "[dotenvx][precommit] ? other install options [https://dotenvx.com/docs/install]"
|
|
79
|
+
exit 1
|
|
80
|
+
fi
|
|
81
|
+
|
|
82
|
+
dotenvx precommit`
|
|
73
83
|
const hookPath = path.join('.git', 'hooks', 'pre-commit')
|
|
74
84
|
|
|
75
85
|
try {
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
|
|
3
|
+
const ignore = require('ignore')
|
|
4
|
+
|
|
5
|
+
const logger = require('./../../shared/logger')
|
|
6
|
+
const helpers = require('./../helpers')
|
|
7
|
+
|
|
8
|
+
function predockerbuild () {
|
|
9
|
+
const options = this.opts()
|
|
10
|
+
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
11
|
+
|
|
12
|
+
// 1. check for .dockerignore file
|
|
13
|
+
if (!fs.existsSync('.dockerignore')) {
|
|
14
|
+
logger.errorvpd('.dockerignore missing')
|
|
15
|
+
logger.help2('? add it with [touch .dockerignore]')
|
|
16
|
+
process.exit(1)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 2. check .env* files against .dockerignore file
|
|
20
|
+
let warningCount = 0
|
|
21
|
+
const ig = ignore().add(fs.readFileSync('.dockerignore').toString())
|
|
22
|
+
const files = fs.readdirSync(process.cwd())
|
|
23
|
+
const dotenvFiles = files.filter(file => file.match(/^\.env(\..+)?$/))
|
|
24
|
+
dotenvFiles.forEach(file => {
|
|
25
|
+
// check if that file is being ignored
|
|
26
|
+
if (ig.ignores(file)) {
|
|
27
|
+
switch (file) {
|
|
28
|
+
case '.env.example':
|
|
29
|
+
warningCount += 1
|
|
30
|
+
logger.warnv(`${file} (currently ignored but should not be)`)
|
|
31
|
+
logger.help2(`? add !${file} to .dockerignore with [echo "!${file}" >> .dockerignore]`)
|
|
32
|
+
break
|
|
33
|
+
case '.env.vault':
|
|
34
|
+
warningCount += 1
|
|
35
|
+
logger.warnv(`${file} (currently ignored but should not be)`)
|
|
36
|
+
logger.help2(`? add !${file} to .dockerignore with [echo "!${file}" >> .dockerignore]`)
|
|
37
|
+
break
|
|
38
|
+
default:
|
|
39
|
+
break
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
switch (file) {
|
|
43
|
+
case '.env.example':
|
|
44
|
+
break
|
|
45
|
+
case '.env.vault':
|
|
46
|
+
break
|
|
47
|
+
default:
|
|
48
|
+
logger.errorvpd(`${file} not properly dockerignored`)
|
|
49
|
+
logger.help2(`? add ${file} to .dockerignore with [echo ".env*" >> .dockerignore]`)
|
|
50
|
+
process.exit(1) // 3.1 exit early with error code
|
|
51
|
+
break
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
// 3. outpout success
|
|
57
|
+
if (warningCount > 0) {
|
|
58
|
+
logger.successvpd(`success (with ${helpers.pluralize('warning', warningCount)})`)
|
|
59
|
+
} else {
|
|
60
|
+
logger.successvpd('success')
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = predockerbuild
|
package/src/cli/actions/run.js
CHANGED
|
@@ -93,6 +93,7 @@ async function run () {
|
|
|
93
93
|
logger.warnv(`missing ${envFilepath} file (${filepath})`)
|
|
94
94
|
logger.help(`? in development: add one with [echo "HELLO=World" > .env] and re-run [dotenvx run -- ${commandArgs.join(' ')}]`)
|
|
95
95
|
logger.help('? for production: set [DOTENV_KEY] on your server and re-deploy')
|
|
96
|
+
logger.help('? for ci: set [DOTENV_KEY] on your ci and re-build')
|
|
96
97
|
break
|
|
97
98
|
|
|
98
99
|
// unhandled error
|
package/src/cli/dotenvx.js
CHANGED
|
@@ -68,11 +68,17 @@ program.command('encrypt')
|
|
|
68
68
|
|
|
69
69
|
// dotenvx precommit
|
|
70
70
|
program.command('precommit')
|
|
71
|
-
.description('
|
|
71
|
+
.description('prevent committing .env files to code')
|
|
72
72
|
.addHelpText('after', examples.precommit)
|
|
73
73
|
.option('-i, --install', 'install to .git/hooks/pre-commit')
|
|
74
74
|
.action(require('./actions/precommit'))
|
|
75
75
|
|
|
76
|
+
// dotenvx predockerbuild
|
|
77
|
+
program.command('predockerbuild')
|
|
78
|
+
.description('prevent including .env files in docker build')
|
|
79
|
+
.addHelpText('after', examples.predockerbuild)
|
|
80
|
+
.action(require('./actions/predockerbuild'))
|
|
81
|
+
|
|
76
82
|
// dotenvx hub
|
|
77
83
|
program.addCommand(require('./commands/hub'))
|
|
78
84
|
|
package/src/cli/examples.js
CHANGED
|
@@ -66,8 +66,26 @@ Try it:
|
|
|
66
66
|
`
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
const predockerbuild = function () {
|
|
70
|
+
return `
|
|
71
|
+
Examples:
|
|
72
|
+
|
|
73
|
+
\`\`\`
|
|
74
|
+
$ dotenvx predockerbuild
|
|
75
|
+
\`\`\`
|
|
76
|
+
|
|
77
|
+
Try it:
|
|
78
|
+
|
|
79
|
+
\`\`\`
|
|
80
|
+
$ dotenvx predockerbuild
|
|
81
|
+
[dotenvx@0.10.0][predockerbuild] success
|
|
82
|
+
\`\`\`
|
|
83
|
+
`
|
|
84
|
+
}
|
|
85
|
+
|
|
69
86
|
module.exports = {
|
|
70
87
|
run,
|
|
71
88
|
encrypt,
|
|
72
|
-
precommit
|
|
89
|
+
precommit,
|
|
90
|
+
predockerbuild
|
|
73
91
|
}
|
package/src/shared/logger.js
CHANGED
|
@@ -12,12 +12,15 @@ const levels = {
|
|
|
12
12
|
error: 0,
|
|
13
13
|
errorv: 0,
|
|
14
14
|
errorvp: 0,
|
|
15
|
+
errorvpd: 0,
|
|
15
16
|
warn: 1,
|
|
16
17
|
warnv: 1,
|
|
17
18
|
warnvp: 1,
|
|
19
|
+
warnvpd: 1,
|
|
18
20
|
success: 2,
|
|
19
21
|
successv: 2,
|
|
20
22
|
successvp: 2,
|
|
23
|
+
successvpd: 2,
|
|
21
24
|
info: 2,
|
|
22
25
|
help: 2,
|
|
23
26
|
help2: 2,
|
|
@@ -48,18 +51,24 @@ const dotenvxFormat = printf(({ level, message, label, timestamp }) => {
|
|
|
48
51
|
return error(`[dotenvx@${packageJson.version}] ${formattedMessage}`)
|
|
49
52
|
case 'errorvp':
|
|
50
53
|
return error(`[dotenvx@${packageJson.version}][precommit] ${formattedMessage}`)
|
|
54
|
+
case 'errorvpd':
|
|
55
|
+
return error(`[dotenvx@${packageJson.version}][predockerbuild] ${formattedMessage}`)
|
|
51
56
|
case 'warn':
|
|
52
57
|
return warn(formattedMessage)
|
|
53
58
|
case 'warnv':
|
|
54
59
|
return warn(`[dotenvx@${packageJson.version}] ${formattedMessage}`)
|
|
55
60
|
case 'warnvp':
|
|
56
61
|
return warn(`[dotenvx@${packageJson.version}][precommit] ${formattedMessage}`)
|
|
62
|
+
case 'warnvpd':
|
|
63
|
+
return warn(`[dotenvx@${packageJson.version}][predockerbuild] ${formattedMessage}`)
|
|
57
64
|
case 'success':
|
|
58
65
|
return success(formattedMessage)
|
|
59
66
|
case 'successv': // success with 'version'
|
|
60
67
|
return successv(`[dotenvx@${packageJson.version}] ${formattedMessage}`)
|
|
61
68
|
case 'successvp': // success with 'version' and precommit
|
|
62
69
|
return success(`[dotenvx@${packageJson.version}][precommit] ${formattedMessage}`)
|
|
70
|
+
case 'successvpd': // success with 'version' and precommit
|
|
71
|
+
return success(`[dotenvx@${packageJson.version}][predockerbuild] ${formattedMessage}`)
|
|
63
72
|
case 'info':
|
|
64
73
|
return formattedMessage
|
|
65
74
|
case 'help':
|