@dotenvx/dotenvx 0.13.0 → 0.14.1
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 +68 -33
- package/package.json +1 -1
- package/src/cli/actions/genexample.js +92 -0
- package/src/cli/actions/gitignore.js +4 -7
- package/src/cli/dotenvx.js +11 -6
package/README.md
CHANGED
|
@@ -423,7 +423,7 @@ More examples
|
|
|
423
423
|
|
|
424
424
|
</details>
|
|
425
425
|
|
|
426
|
-
* <details><summary>Docker
|
|
426
|
+
* <details><summary>Docker 🐳</summary><br>
|
|
427
427
|
|
|
428
428
|
> Add the `dotenvx` binary to your Dockerfile
|
|
429
429
|
|
|
@@ -443,15 +443,27 @@ More examples
|
|
|
443
443
|
|
|
444
444
|
</details>
|
|
445
445
|
|
|
446
|
-
* <details><summary>Fly.io
|
|
446
|
+
* <details><summary>Fly.io 🎈</summary><br>
|
|
447
|
+
|
|
448
|
+
> Add the `dotenvx` binary to your Dockerfile
|
|
447
449
|
|
|
448
450
|
```sh
|
|
449
|
-
|
|
451
|
+
# Install dotenvx
|
|
452
|
+
RUN curl -fsS https://dotenvx.sh/ | sh
|
|
450
453
|
```
|
|
451
454
|
|
|
455
|
+
> Use it in your Dockerfile CMD
|
|
456
|
+
|
|
457
|
+
```sh
|
|
458
|
+
# Prepend dotenvx run
|
|
459
|
+
CMD ["dotenvx", "run", "--", "node", "index.js"]
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
see [fly guide](https://dotenvx.com/docs/platforms/fly)
|
|
463
|
+
|
|
452
464
|
</details>
|
|
453
465
|
|
|
454
|
-
* <details><summary>Heroku
|
|
466
|
+
* <details><summary>Heroku 🟣</summary><br>
|
|
455
467
|
|
|
456
468
|
> Add the buildpack, installing the `dotenvx` binary to your heroku deployment.
|
|
457
469
|
|
|
@@ -477,20 +489,47 @@ More examples
|
|
|
477
489
|
|
|
478
490
|
</details>
|
|
479
491
|
|
|
480
|
-
* <details><summary>Netlify
|
|
492
|
+
* <details><summary>Netlify 🔷</summary><br>
|
|
493
|
+
|
|
494
|
+
> Add the `dotenvx` npm module
|
|
481
495
|
|
|
482
496
|
```sh
|
|
483
|
-
|
|
497
|
+
npm install @dotenvx/dotenvx --save
|
|
484
498
|
```
|
|
485
499
|
|
|
500
|
+
> Use it in your `package.json scripts`
|
|
501
|
+
|
|
502
|
+
```json
|
|
503
|
+
"scripts": {
|
|
504
|
+
"dotenvx": "dotenvx",
|
|
505
|
+
"dev": "dotenvx run -- next dev --turbo",
|
|
506
|
+
"build": "dotenvx run -- next build",
|
|
507
|
+
"start": "dotenvx run -- next start"
|
|
508
|
+
},
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
see [netlify guide](https://dotenvx.com/docs/platforms/netlify)
|
|
512
|
+
|
|
486
513
|
</details>
|
|
487
514
|
|
|
488
|
-
* <details><summary>Railway
|
|
515
|
+
* <details><summary>Railway 🚄</summary><br>
|
|
516
|
+
|
|
517
|
+
> Add the `dotenvx` binary to your Dockerfile
|
|
489
518
|
|
|
490
519
|
```sh
|
|
491
|
-
|
|
520
|
+
# Install dotenvx
|
|
521
|
+
RUN curl -fsS https://dotenvx.sh/ | sh
|
|
492
522
|
```
|
|
493
523
|
|
|
524
|
+
> Use it in your Dockerfile CMD
|
|
525
|
+
|
|
526
|
+
```sh
|
|
527
|
+
# Prepend dotenvx run
|
|
528
|
+
CMD ["dotenvx", "run", "--", "node", "index.js"]
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
see [railway guide](https://dotenvx.com/docs/platforms/railway)
|
|
532
|
+
|
|
494
533
|
</details>
|
|
495
534
|
|
|
496
535
|
* <details><summary>Render</summary><br>
|
|
@@ -501,7 +540,7 @@ More examples
|
|
|
501
540
|
|
|
502
541
|
</details>
|
|
503
542
|
|
|
504
|
-
* <details><summary>Vercel
|
|
543
|
+
* <details><summary>Vercel ▲</summary><br>
|
|
505
544
|
|
|
506
545
|
> Add the `dotenvx` npm module
|
|
507
546
|
|
|
@@ -532,7 +571,7 @@ More examples
|
|
|
532
571
|
|
|
533
572
|
</details>
|
|
534
573
|
|
|
535
|
-
* <details><summary>GitHub Actions
|
|
574
|
+
* <details><summary>GitHub Actions 🐙</summary><br>
|
|
536
575
|
|
|
537
576
|
> Add the `dotenvx` binary to GitHub Actions
|
|
538
577
|
|
|
@@ -561,42 +600,38 @@ More examples
|
|
|
561
600
|
|
|
562
601
|
## Hub
|
|
563
602
|
|
|
564
|
-
> Integrate tightly with [GitHub](https://github.com) 🐙
|
|
603
|
+
> Integrate tightly with [GitHub](https://github.com) 🐙 and as a team
|
|
565
604
|
```sh
|
|
566
605
|
$ dotenvx hub login
|
|
567
606
|
$ dotenvx hub push
|
|
568
607
|
```
|
|
569
608
|
|
|
570
|
-
more details coming soon.
|
|
609
|
+
**beta**: more details coming soon.
|
|
571
610
|
|
|
572
611
|
|
|
573
612
|
|
|
574
|
-
##
|
|
613
|
+
## More features
|
|
575
614
|
|
|
576
|
-
|
|
577
|
-
* [quickstart guide](https://dotenvx.com/docs/quickstart)
|
|
615
|
+
> Keep your `.env` files safe
|
|
578
616
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
You can prevent `.env` files from being committed to code with this pre-commit hook.
|
|
584
|
-
|
|
585
|
-
```
|
|
586
|
-
dotenvx precommit --install
|
|
587
|
-
```
|
|
588
|
-
|
|
589
|
-
Run without the `--install` flag to preview output.
|
|
617
|
+
* [`dotenvx genexample`](https://dotenvx.com/docs/features/genexample) – generate `.env.example` file
|
|
618
|
+
* [`dotenvx gitignore`](https://dotenvx.com/docs/features/gitignore) – gitignore your `.env` files
|
|
619
|
+
* [`dotenvx prebuild`](https://dotenvx.com/docs/features/prebuild) – prevent `.env` files from being built into your docker container
|
|
620
|
+
* [`dotenvx precommit`](https://dotenvx.com/docs/features/precommit) – prevent `.env` files from being committed to code
|
|
590
621
|
|
|
591
|
-
|
|
592
|
-
dotenvx precommit
|
|
593
|
-
```
|
|
622
|
+
|
|
594
623
|
|
|
595
|
-
|
|
624
|
+
## Guides
|
|
596
625
|
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
626
|
+
* [quickstart guides](https://dotenvx.com/docs/quickstart)
|
|
627
|
+
* [run anywhere](https://dotenvx.com/docs/quickstart/run)
|
|
628
|
+
* [multi-environment](https://dotenvx.com/docs/quickstart/environments)
|
|
629
|
+
* [encrypted envs](https://dotenvx.com/docs/quickstart/encryption)
|
|
630
|
+
* [dotenvx/docs](https://dotenvx.com/docs)
|
|
631
|
+
* [languages](https://dotenvx.com/docs#languages)
|
|
632
|
+
* [frameworks](https://dotenvx.com/docs#frameworks)
|
|
633
|
+
* [platforms](https://dotenvx.com/docs#platforms)
|
|
634
|
+
* [ci/cd](https://dotenvx.com/docs#cis)
|
|
600
635
|
|
|
601
636
|
|
|
602
637
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const helpers = require('./../helpers')
|
|
3
|
+
const main = require('./../../lib/main')
|
|
4
|
+
const logger = require('./../../shared/logger')
|
|
5
|
+
const createSpinner = require('./../../shared/createSpinner')
|
|
6
|
+
|
|
7
|
+
const spinner = createSpinner('generating')
|
|
8
|
+
|
|
9
|
+
const ENCODING = 'utf8'
|
|
10
|
+
|
|
11
|
+
async function genexample () {
|
|
12
|
+
spinner.start()
|
|
13
|
+
await helpers.sleep(500) // better dx
|
|
14
|
+
|
|
15
|
+
const options = this.opts()
|
|
16
|
+
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
17
|
+
|
|
18
|
+
let optionEnvFile = options.envFile
|
|
19
|
+
if (!Array.isArray(optionEnvFile)) {
|
|
20
|
+
optionEnvFile = [optionEnvFile]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// must be at least one .env* file
|
|
24
|
+
if (optionEnvFile.length < 1) {
|
|
25
|
+
spinner.fail('no .env* files found')
|
|
26
|
+
logger.help('? add one with [echo "HELLO=World" > .env] and then run [dotenvx genexample]')
|
|
27
|
+
process.exit(1)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const keys = new Set()
|
|
31
|
+
const addedKeys = new Set()
|
|
32
|
+
|
|
33
|
+
for (const envFilepath of optionEnvFile) {
|
|
34
|
+
const filepath = helpers.resolvePath(envFilepath)
|
|
35
|
+
|
|
36
|
+
logger.verbose(`loading env from ${filepath}`)
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const src = fs.readFileSync(filepath, { encoding: ENCODING })
|
|
40
|
+
const parsed = main.parse(src)
|
|
41
|
+
Object.keys(parsed).forEach(key => { keys.add(key) })
|
|
42
|
+
} catch (e) {
|
|
43
|
+
// calculate development help message depending on state of repo
|
|
44
|
+
const vaultFilepath = helpers.resolvePath('.env.vault')
|
|
45
|
+
let developmentHelp = '? in development: add one with [echo "HELLO=World" > .env] and re-run [dotenvx genexample]'
|
|
46
|
+
if (fs.existsSync(vaultFilepath)) {
|
|
47
|
+
developmentHelp = '? in development: use [dotenvx decrypt] to decrypt .env.vault to .env and then re-run [dotenvx genexample]'
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
switch (e.code) {
|
|
51
|
+
// missing .env
|
|
52
|
+
case 'ENOENT':
|
|
53
|
+
logger.warn(`missing ${envFilepath} file (${filepath})`)
|
|
54
|
+
logger.help(developmentHelp)
|
|
55
|
+
break
|
|
56
|
+
|
|
57
|
+
// unhandled error
|
|
58
|
+
default:
|
|
59
|
+
logger.warn(e)
|
|
60
|
+
break
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const exampleFilename = '.env.example'
|
|
66
|
+
const exampleFilepath = helpers.resolvePath(exampleFilename)
|
|
67
|
+
if (!fs.existsSync(exampleFilepath)) {
|
|
68
|
+
logger.verbose(`creating ${exampleFilename}`)
|
|
69
|
+
fs.writeFileSync(exampleFilename, `# ${exampleFilename}\n`)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const currentEnvExample = (main.configDotenv({ path: exampleFilepath }).parsed || {})
|
|
73
|
+
const keysArray = Array.from(keys)
|
|
74
|
+
|
|
75
|
+
keysArray.forEach(key => {
|
|
76
|
+
if (key in currentEnvExample) {
|
|
77
|
+
logger.verbose(`pre-existing ${key} in ${exampleFilename}`)
|
|
78
|
+
} else {
|
|
79
|
+
addedKeys.add(key)
|
|
80
|
+
logger.verbose(`appending ${key} to ${exampleFilename}`)
|
|
81
|
+
fs.appendFileSync('.env.example', `${key}=""\n`, ENCODING)
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
if (addedKeys.size > 0) {
|
|
86
|
+
spinner.succeed(`updated ${exampleFilename} (${addedKeys.size})`)
|
|
87
|
+
} else {
|
|
88
|
+
spinner.done(`no changes (${exampleFilename})`)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports = genexample
|
|
@@ -38,24 +38,28 @@ class Generic {
|
|
|
38
38
|
|
|
39
39
|
class Git {
|
|
40
40
|
run () {
|
|
41
|
+
logger.verbose('appending to .gitignore')
|
|
41
42
|
new Generic('.gitignore', true).run()
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
class Docker {
|
|
46
47
|
run () {
|
|
48
|
+
logger.verbose('appending to .dockerignore (if existing)')
|
|
47
49
|
new Generic('.dockerignore').run()
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
class Npm {
|
|
52
54
|
run () {
|
|
55
|
+
logger.verbose('appending to .npmignore (if existing)')
|
|
53
56
|
new Generic('.npmignore').run()
|
|
54
57
|
}
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
class Vercel {
|
|
58
61
|
run () {
|
|
62
|
+
logger.verbose('appending to .vercelignore (if existing)')
|
|
59
63
|
new Generic('.vercelignore').run()
|
|
60
64
|
}
|
|
61
65
|
}
|
|
@@ -64,16 +68,9 @@ function gitignore () {
|
|
|
64
68
|
const options = this.opts()
|
|
65
69
|
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
66
70
|
|
|
67
|
-
logger.verbose('appending to .gitignore')
|
|
68
71
|
new Git().run()
|
|
69
|
-
|
|
70
|
-
logger.verbose('appending to .dockerignore (if existing)')
|
|
71
72
|
new Docker().run()
|
|
72
|
-
|
|
73
|
-
logger.verbose('appending to .npmignore (if existing)')
|
|
74
73
|
new Npm().run()
|
|
75
|
-
|
|
76
|
-
logger.verbose('appending to .vercelignore (if existing)')
|
|
77
74
|
new Vercel().run()
|
|
78
75
|
|
|
79
76
|
logger.success('done')
|
package/src/cli/dotenvx.js
CHANGED
|
@@ -69,9 +69,14 @@ program.command('encrypt')
|
|
|
69
69
|
// dotenvx decrypt
|
|
70
70
|
program.command('decrypt')
|
|
71
71
|
.description('decrypt .env.vault to .env*')
|
|
72
|
-
.addHelpText('after', examples.encrypt)
|
|
73
72
|
.action(require('./actions/decrypt'))
|
|
74
73
|
|
|
74
|
+
// dotenvx gitignore
|
|
75
|
+
program.command('gitignore')
|
|
76
|
+
.description('append to .gitignore file (and if existing, .dockerignore, .npmignore, and .vercelignore)')
|
|
77
|
+
.addHelpText('after', examples.gitignore)
|
|
78
|
+
.action(require('./actions/gitignore'))
|
|
79
|
+
|
|
75
80
|
// dotenvx precommit
|
|
76
81
|
program.command('precommit')
|
|
77
82
|
.description('prevent committing .env files to code')
|
|
@@ -85,11 +90,11 @@ program.command('prebuild')
|
|
|
85
90
|
.addHelpText('after', examples.prebuild)
|
|
86
91
|
.action(require('./actions/prebuild'))
|
|
87
92
|
|
|
88
|
-
// dotenvx
|
|
89
|
-
program.command('
|
|
90
|
-
.description('
|
|
91
|
-
.
|
|
92
|
-
.action(require('./actions/
|
|
93
|
+
// dotenvx genexample
|
|
94
|
+
program.command('genexample')
|
|
95
|
+
.description('generate .env.example')
|
|
96
|
+
.option('-f, --env-file <paths...>', 'path(s) to your env file(s)', '.env')
|
|
97
|
+
.action(require('./actions/genexample'))
|
|
93
98
|
|
|
94
99
|
// dotenvx hub
|
|
95
100
|
program.addCommand(require('./commands/hub'))
|