@dotenvx/dotenvx 0.10.3 → 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 +82 -6
- package/package.json +1 -1
- package/src/cli/actions/predockerbuild.js +64 -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
|
|
|
@@ -408,10 +448,25 @@ More examples
|
|
|
408
448
|
|
|
409
449
|
* <details><summary>Vercel</summary><br>
|
|
410
450
|
|
|
451
|
+
> Add the `dotenvx` npm module
|
|
452
|
+
|
|
411
453
|
```sh
|
|
412
|
-
|
|
454
|
+
npm install @dotenvx/dotenvx --save
|
|
455
|
+
```
|
|
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
|
+
},
|
|
413
466
|
```
|
|
414
467
|
|
|
468
|
+
see [vercel guide](https://dotenvx.com/docs/platforms/vercel)
|
|
469
|
+
|
|
415
470
|
</details>
|
|
416
471
|
|
|
417
472
|
* <details><summary>CircleCI</summary><br>
|
|
@@ -424,10 +479,27 @@ More examples
|
|
|
424
479
|
|
|
425
480
|
* <details><summary>GitHub Actions</summary><br>
|
|
426
481
|
|
|
482
|
+
> Add the `dotenvx` binary to GitHub Actions
|
|
483
|
+
|
|
427
484
|
```sh
|
|
428
|
-
|
|
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 }}
|
|
429
499
|
```
|
|
430
500
|
|
|
501
|
+
see [github actions guide](https://dotenvx.com/docs/cis/github-actions)
|
|
502
|
+
|
|
431
503
|
</details>
|
|
432
504
|
|
|
433
505
|
|
|
@@ -449,6 +521,8 @@ more details coming soon.
|
|
|
449
521
|
* [dotenvx/docs](https://dotenvx.com/docs)
|
|
450
522
|
* [quickstart guide](https://dotenvx.com/docs/quickstart)
|
|
451
523
|
|
|
524
|
+
|
|
525
|
+
|
|
452
526
|
## Pre-commit
|
|
453
527
|
|
|
454
528
|
You can prevent `.env` files from being committed to code with this pre-commit hook.
|
|
@@ -469,6 +543,8 @@ To ignore the pre-commit hook run your git commit with the `--no-verify` flag.
|
|
|
469
543
|
git commit -am "msg" --no-verify
|
|
470
544
|
```
|
|
471
545
|
|
|
546
|
+
|
|
547
|
+
|
|
472
548
|
## Contributing
|
|
473
549
|
|
|
474
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
|
@@ -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/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':
|