@dotenvx/dotenvx 0.6.4 → 0.6.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 CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  *a better dotenv*–from the creator of [`dotenv`](https://github.com/motdotla/dotenv).
4
4
 
5
- * [run anywhere](#run-anywhere) (cross-platform)
6
- * [multi-environment](#multiple-environments)
7
- * [encrypted envs](#encryption)
5
+ * run anywhere (cross-platform)
6
+ * multi-environment
7
+ * encrypted envs
8
8
 
9
9
   
10
10
 
@@ -21,7 +21,8 @@ brew install dotenvx/brew/dotenvx
21
21
  ## Run Anywhere
22
22
 
23
23
  ```sh
24
- $ echo "HELLO=World" > .env && echo "console.log('Hello ' + process.env.HELLO)" > index.js
24
+ $ echo "HELLO=World" > .env
25
+ $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
25
26
 
26
27
  $ node index.js
27
28
  Hello undefined
@@ -36,7 +37,8 @@ More examples
36
37
  * <details><summary>Python 🐍</summary><br>
37
38
 
38
39
  ```sh
39
- $ echo "HELLO=World" > .env && echo 'import os;print("Hello " + os.getenv("HELLO", ""))' > index.py
40
+ $ echo "HELLO=World" > .env
41
+ $ echo 'import os;print("Hello " + os.getenv("HELLO", ""))' > index.py
40
42
 
41
43
  $ dotenvx run -- python3 index.py
42
44
  Hello World
@@ -46,7 +48,8 @@ More examples
46
48
  * <details><summary>PHP 🐘</summary><br>
47
49
 
48
50
  ```sh
49
- $ echo "HELLO=World" > .env && echo '<?php echo "Hello {$_SERVER["HELLO"]}\n";' > index.php
51
+ $ echo "HELLO=World" > .env
52
+ $ echo '<?php echo "Hello {$_SERVER["HELLO"]}\n";' > index.php
50
53
 
51
54
  $ dotenvx run -- php index.php
52
55
  Hello World
@@ -56,17 +59,30 @@ More examples
56
59
  * <details><summary>Ruby 💎</summary><br>
57
60
 
58
61
  ```sh
59
- $ echo "HELLO=World" > .env && echo 'puts "Hello #{ENV["HELLO"]}"' > index.rb
62
+ $ echo "HELLO=World" > .env
63
+ $ echo 'puts "Hello #{ENV["HELLO"]}"' > index.rb
60
64
 
61
65
  $ dotenvx run -- ruby index.rb
62
66
  Hello World
63
67
  ```
64
68
 
69
+ </details>
70
+ * <details><summary>Go 🐹</summary><br>
71
+
72
+ ```sh
73
+ $ echo "HELLO=World" > .env
74
+ $ echo 'package main; import ("fmt"; "os"); func main() { fmt.Printf("Hello %s\n", os.Getenv("HELLO")) }' > main.go
75
+
76
+ $ dotenvx run -- go run main.go
77
+ Hello World
78
+ ```
79
+
65
80
  </details>
66
81
  * <details><summary>Rust 🦀</summary><br>
67
82
 
68
83
  ```sh
69
- $ echo "HELLO=World" > .env && echo 'fn main() {let hello = std::env::var("HELLO").unwrap_or("".to_string());println!("Hello {hello}");}' > src/main.rs
84
+ $ echo "HELLO=World" > .env
85
+ $ echo 'fn main() {let hello = std::env::var("HELLO").unwrap_or("".to_string());println!("Hello {hello}");}' > src/main.rs
70
86
 
71
87
  $ dotenvx run -- cargo run
72
88
  Hello World
@@ -76,7 +92,8 @@ More examples
76
92
  * <details><summary>Java ☕️</summary><br>
77
93
 
78
94
  ```sh
79
- $ echo "HELLO=World" > .env && echo 'public class Index { public static void main(String[] args) { System.out.println("Hello " + System.getenv("HELLO")); } }' > index.java
95
+ $ echo "HELLO=World" > .env
96
+ $ echo 'public class Index { public static void main(String[] args) { System.out.println("Hello " + System.getenv("HELLO")); } }' > index.java
80
97
 
81
98
  $ dotenvx run -- java index.java
82
99
  Hello World
@@ -88,7 +105,8 @@ More examples
88
105
  ```sh
89
106
  $ dotnet new console -n HelloWorld -o HelloWorld
90
107
  $ cd HelloWorld
91
- $ echo "HELLO=World" > .env && echo 'Console.WriteLine($"Hello {Environment.GetEnvironmentVariable("HELLO")}");' > Program.cs && echo "HELLO=World" > .env
108
+ $ echo "HELLO=World" > .env
109
+ $ echo 'Console.WriteLine($"Hello {Environment.GetEnvironmentVariable("HELLO")}");' > Program.cs
92
110
 
93
111
  $ dotenvx run -- dotnet run
94
112
  Hello World
@@ -169,7 +187,7 @@ More examples
169
187
  > start
170
188
  > ./node_modules/.bin/dotenvx run -- node index.js
171
189
 
172
- [dotenvx][INFO] injecting 1 environment variable from .env
190
+ [dotenvx][info] loading env (1) from .env
173
191
  Hello World
174
192
  ```
175
193
 
@@ -192,9 +210,11 @@ More examples
192
210
 
193
211
  > Create a `.env.production` file and use `--env-file` to load it. It's straightforward, yet flexible.
194
212
  ```sh
195
- $ echo "HELLO=production" > .env.production && echo "console.log('Hello ' + process.env.HELLO)" > index.js
213
+ $ echo "HELLO=production" > .env.production
214
+ $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
196
215
 
197
216
  $ dotenvx run --env-file=.env.production -- node index.js
217
+ [dotenvx][info] loading env (1) from .env.production
198
218
  Hello production
199
219
  > ^^
200
220
  ```
@@ -209,6 +229,7 @@ More examples
209
229
  $ echo "HELLO=World" > .env
210
230
 
211
231
  $ dotenvx run --env-file=.env.local --env-file=.env -- node index.js
232
+ [dotenvx][info] loading env (1) from .env.local,.env
212
233
  Hello local
213
234
  ```
214
235
 
@@ -222,6 +243,7 @@ More examples
222
243
  $ echo "HELLO=World" > .env
223
244
 
224
245
  $ dotenvx run --env-file=.env.local --env-file=.env --overload -- node index.js
246
+ [dotenvx][info] loading env (1) from .env.local,.env
225
247
  Hello World
226
248
  ```
227
249
 
@@ -231,9 +253,9 @@ More examples
231
253
  $ echo "HELLO=production" > .env.production
232
254
 
233
255
  $ dotenvx run --env-file=.env.production --verbose -- node index.js
234
- [dotenvx][VERBOSE] injecting env from /path/to/.env.production
235
- [dotenvx][VERBOSE] HELLO set
236
- [dotenvx][INFO] injecting 1 environment variable from .env.production
256
+ [dotenvx][verbose] injecting env from /path/to/.env.production
257
+ [dotenvx][verbose] HELLO set
258
+ [dotenvx][info] loading env (1) from .env.production
237
259
  Hello production
238
260
  ```
239
261
 
@@ -243,16 +265,16 @@ More examples
243
265
  $ echo "HELLO=production" > .env.production
244
266
 
245
267
  $ dotenvx run --env-file=.env.production --debug -- node index.js
246
- [dotenvx][DEBUG] configuring options
247
- [dotenvx][DEBUG] {"envFile":[".env.production"]}
248
- [dotenvx][VERBOSE] injecting env from /path/to/.env.production
249
- [dotenvx][DEBUG] reading env from /path/to/.env.production
250
- [dotenvx][DEBUG] parsing env from /path/to/.env.production
251
- [dotenvx][DEBUG] {"HELLO":"production"}
252
- [dotenvx][DEBUG] writing env from /path/to/.env.production
253
- [dotenvx][VERBOSE] HELLO set
254
- [dotenvx][DEBUG] HELLO set to production
255
- [dotenvx][INFO] injecting 1 environment variable from .env.production
268
+ [dotenvx][debug] configuring options
269
+ [dotenvx][debug] {"envFile":[".env.production"]}
270
+ [dotenvx][verbose] injecting env from /path/to/.env.production
271
+ [dotenvx][debug] reading env from /path/to/.env.production
272
+ [dotenvx][debug] parsing env from /path/to/.env.production
273
+ [dotenvx][debug] {"HELLO":"production"}
274
+ [dotenvx][debug] writing env from /path/to/.env.production
275
+ [dotenvx][verbose] HELLO set
276
+ [dotenvx][debug] HELLO set to production
277
+ [dotenvx][info] loading env (1) from .env.production
256
278
  Hello production
257
279
  ```
258
280
 
@@ -262,43 +284,20 @@ More examples
262
284
 
263
285
  ## Encryption
264
286
 
265
- > Encrypt your secrets to a `.env.vault` file.
266
- ```
267
- $ echo "HELLO=World" > .env && echo "console.log('Hello ' + process.env.HELLO)" > index.js
268
-
287
+ > Encrypt your secrets to a `.env.vault` file and load from it (recommended for production and ci).
288
+ ```sh
289
+ $ echo "HELLO=World" > .env
269
290
  $ echo "HELLO=production" > .env.production
291
+ $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
270
292
 
271
293
  $ dotenvx encrypt
272
- [dotenvx][INFO] encrypted .env,.env.production to .env.vault
273
- [dotenvx][INFO]
274
- [dotenvx][INFO] try it out:
275
- [dotenvx][INFO]
276
- [dotenvx][INFO] DOTENV_KEY='<DOTENV_KEY_ENVIRONMENT>' dotenvx run -- node index.js
277
- [dotenvx][INFO]
278
- [dotenvx][INFO] next:
279
- [dotenvx][INFO]
280
- [dotenvx][INFO] 1. commit .env.vault safely to code
281
- [dotenvx][INFO] 2. set DOTENV_KEY on server (or ci)
282
- [dotenvx][INFO] 3. push your code
283
- [dotenvx][INFO]
284
- [dotenvx][INFO] tips:
285
- [dotenvx][INFO]
286
- [dotenvx][INFO] * .env.keys file holds your decryption DOTENV_KEYs
287
- [dotenvx][INFO] * DO NOT commit .env.keys to code
288
- [dotenvx][INFO] * share .env.keys file over secure channels only
289
- > :-]
290
- ```
291
-
292
- &nbsp;
294
+ [dotenvx][info] encrypted to .env.vault (.env,.env.production)
295
+ [dotenvx][info] keys added to .env.keys (DOTENV_KEY_PRODUCTION,DOTENV_KEY_PRODUCTION)
293
296
 
294
- > Then load env from encrypted `.env.vault` file
295
-
296
- ```sh
297
- $ DOTENV_KEY='dotenv://:key_abc123@dotenvx.com/vault/.env.vault?environment=production' dotenvx run -- node index.js
298
- [dotenvx][INFO] injecting 1 environment variable from encrypted .env.vault
297
+ $ DOTENV_KEY='<dotenv_key_production>' dotenvx run -- node index.js
298
+ [dotenvx][info] loading env (1) from encrypted .env.vault
299
299
  Hello production
300
-
301
- > :-]
300
+ ^ :-]
302
301
  ```
303
302
 
304
303
  More examples
@@ -402,81 +401,10 @@ More examples
402
401
 
403
402
  &nbsp;
404
403
 
405
- ---
406
-
407
- ## Usage
408
-
409
- ### Guide
410
-
411
- Begin by creating a simple 'hello world' program.
412
-
413
- ```js
414
- // index.js
415
- console.log(`Hello ${process.env.HELLO}`)
416
- ```
417
-
418
- Run it.
419
-
420
- ```js
421
- $ node index.js
422
- Hello undefined
423
- ```
424
-
425
- Run it with `dotenvx`.
426
-
427
- ```sh
428
- $ dotenvx run -- node index.js
429
- [dotenvx][WARN] ENOENT: no such file or directory, open '/../../.env'
430
- Hello undefined
431
- ```
432
-
433
- It warns you when there is no `.env` file (pass the `--quiet` flag to suppress these warnings).
434
-
435
- Create the `.env` file.
436
-
437
- ```ini
438
- # env
439
- JELLO="World"
440
- ```
441
-
442
- Run it again.
443
-
444
- ```sh
445
- $ dotenvx run -- node index.js
446
- [dotenvx][INFO] injecting 0 environment variables from .env
447
- Hello undefined
448
- ```
404
+ ## Guides
449
405
 
450
- Hrm, still undefined. Pass the `--debug` flag to debug the issue. I'll give you a hint: 🍮
451
-
452
- ```sh
453
- $ dotenvx run --debug -- node index.js
454
- [dotenvx][VERBOSE] Loading env from /../../.env
455
- [dotenvx][DEBUG] Reading env from /../../.env
456
- [dotenvx][DEBUG] Parsing env from /../../.env
457
- [dotenvx][DEBUG] {"JELLO":"World"}
458
-
459
- # Oops, HELLO not JELLO ^^
460
- ```
461
-
462
- Fix your `.env` file.
463
-
464
- ```ini
465
- # .env
466
- HELLO="World"
467
- ```
468
-
469
- One last time. [Le tired](https://youtu.be/kCpjgl2baLs?t=45).
470
-
471
- ```sh
472
- $ dotenvx run -- node index.js
473
- [dotenvx][INFO] injecting 1 environment variable from .env
474
- Hello World
475
- ```
476
-
477
- 🎉 It worked!
478
-
479
- &nbsp;
406
+ * [dotenvx/docs](https://dotenvx.com/docs)
407
+ * [quickstart guide](https://dotenvx.com/docs/quickstart)
480
408
 
481
409
  ## Contributing
482
410
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.6.4",
2
+ "version": "0.6.6",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -9,6 +9,7 @@ const ENCODING = 'utf8'
9
9
 
10
10
  const logger = require('./../shared/logger')
11
11
  const helpers = require('./helpers')
12
+ const examples = require('./examples')
12
13
  const { AppendToIgnores } = require('./ignores')
13
14
  const packageJson = require('./../shared/packageJson')
14
15
  const main = require('./../lib/main')
@@ -53,7 +54,8 @@ program
53
54
 
54
55
  // dotenvx run -- node index.js
55
56
  program.command('run')
56
- .description('inject env variables into your application process')
57
+ .description('inject env at runtime (example: `dotenvx run -- your-cmd`)')
58
+ .addHelpText('after', examples.run)
57
59
  .option('-f, --env-file <paths...>', 'path(s) to your env file(s)', '.env')
58
60
  .option('-o, --overload', 'override existing env variables')
59
61
  .action(function () {
@@ -68,7 +70,7 @@ program.command('run')
68
70
  if (!fs.existsSync(filepath)) {
69
71
  logger.error(`you set DOTENV_KEY but your .env.vault file is missing: ${filepath}`)
70
72
  } else {
71
- logger.verbose(`injecting encrypted env from ${filepath}`)
73
+ logger.verbose(`loading env from encrypted ${filepath}`)
72
74
 
73
75
  try {
74
76
  logger.debug(`reading encrypted env from ${filepath}`)
@@ -112,7 +114,7 @@ program.command('run')
112
114
  logger.debug(`writing decrypted env from ${filepath}`)
113
115
  const result = main.write(process.env, parsed, options.overload)
114
116
 
115
- logger.info(`injecting ${result.written.size} environment ${helpers.pluralize('variable', result.written.size)} from encrypted .env.vault`)
117
+ logger.info(`loading env (${result.written.size}) from encrypted .env.vault`)
116
118
  } catch (e) {
117
119
  logger.error(e)
118
120
  }
@@ -130,7 +132,7 @@ program.command('run')
130
132
  for (const envFilepath of optionEnvFile) {
131
133
  const filepath = helpers.resolvePath(envFilepath)
132
134
 
133
- logger.verbose(`injecting env from ${filepath}`)
135
+ logger.verbose(`loading env from ${filepath}`)
134
136
 
135
137
  try {
136
138
  logger.debug(`reading env from ${filepath}`)
@@ -150,7 +152,7 @@ program.command('run')
150
152
  }
151
153
 
152
154
  if (readableFilepaths.size > 0) {
153
- logger.info(`injecting ${written.size} environment ${helpers.pluralize('variable', written.size)} from ${[...readableFilepaths]}`)
155
+ logger.info(`loading env (${written.size}) from ${[...readableFilepaths]}`)
154
156
  }
155
157
  }
156
158
 
@@ -169,6 +171,7 @@ program.command('run')
169
171
  // dotenvx encrypt
170
172
  program.command('encrypt')
171
173
  .description('encrypt .env.* to .env.vault')
174
+ .addHelpText('after', examples.encrypt)
172
175
  .option('-f, --env-file <paths...>', 'path(s) to your env file(s)', helpers.findEnvFiles('./'))
173
176
  .action(function () {
174
177
  const options = this.opts()
@@ -180,6 +183,8 @@ program.command('encrypt')
180
183
  optionEnvFile = [optionEnvFile]
181
184
  }
182
185
 
186
+ const addedKeys = new Set()
187
+
183
188
  try {
184
189
  logger.verbose(`generating .env.keys from ${optionEnvFile}`)
185
190
 
@@ -203,6 +208,8 @@ program.command('encrypt')
203
208
  logger.debug(`generating ${key} as ${value}`)
204
209
 
205
210
  dotenvKeys[key] = value
211
+
212
+ addedKeys.add(key) // for info logging to user
206
213
  } else {
207
214
  logger.verbose(`existing ${key}`)
208
215
  logger.debug(`existing ${key} as ${value}`)
@@ -269,23 +276,26 @@ program.command('encrypt')
269
276
  process.exit(1)
270
277
  }
271
278
 
272
- logger.info(`encrypted ${optionEnvFile} to .env.vault`)
273
- logger.info('')
274
- logger.info('try it out:')
275
- logger.info('')
276
- logger.info(' DOTENV_KEY=\'<DOTENV_KEY_ENVIRONMENT>\' dotenvx run -- node index.js')
277
- logger.info('')
278
- logger.info('next:')
279
- logger.info('')
280
- logger.info(' 1. commit .env.vault safely to code')
281
- logger.info(' 2. set DOTENV_KEY on server (or ci)')
282
- logger.info(' 3. push your code')
283
- logger.info('')
284
- logger.info('tips:')
285
- logger.info('')
286
- logger.info(' * .env.keys file holds your decryption DOTENV_KEYs')
287
- logger.info(' * DO NOT commit .env.keys to code')
288
- logger.info(' * share .env.keys file over secure channels only')
279
+ logger.info(`encrypted to .env.vault (${optionEnvFile})`)
280
+ if (addedKeys.size > 0) {
281
+ logger.info(`${helpers.pluralize('key', addedKeys.size)} added to .env.keys (${[...addedKeys]})`)
282
+ }
283
+ logger.verbose('')
284
+ logger.verbose('try it out:')
285
+ logger.verbose('')
286
+ logger.verbose(' DOTENV_KEY=\'<DOTENV_KEY_ENVIRONMENT>\' dotenvx run -- node index.js')
287
+ logger.verbose('')
288
+ logger.verbose('next:')
289
+ logger.verbose('')
290
+ logger.verbose(' 1. commit .env.vault safely to code')
291
+ logger.verbose(' 2. set DOTENV_KEY on server (or ci)')
292
+ logger.verbose(' 3. push your code')
293
+ logger.verbose('')
294
+ logger.verbose('tips:')
295
+ logger.verbose('')
296
+ logger.verbose(' * .env.keys file holds your decryption DOTENV_KEYs')
297
+ logger.verbose(' * DO NOT commit .env.keys to code')
298
+ logger.verbose(' * share .env.keys file over secure channels only')
289
299
  })
290
300
 
291
301
  program.parse(process.argv)
@@ -0,0 +1,51 @@
1
+ const run = function () {
2
+ return `
3
+ Example:
4
+
5
+ \`\`\`sh
6
+ $ dotenvx run -- your-cmd
7
+ \`\`\`
8
+
9
+ Try it:
10
+
11
+ \`\`\`sh
12
+ $ echo "HELLO=World" > .env
13
+ $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
14
+
15
+ $ dotenvx run -- node index.js
16
+ [dotenvx][info] loading env (1) from .env
17
+ Hello World
18
+ \`\`\`
19
+ `
20
+ }
21
+
22
+ const encrypt = function () {
23
+ return `
24
+ Example:
25
+
26
+ \`\`\`sh
27
+ $ dotenvx encrypt
28
+ \`\`\`
29
+
30
+ Try it:
31
+
32
+ \`\`\`sh
33
+ $ echo "HELLO=World" > .env
34
+ $ echo "HELLO=production" > .env.production
35
+ $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
36
+
37
+ $ dotenvx encrypt
38
+ [dotenvx][info] encrypted to .env.vault (.env,.env.production)
39
+ [dotenvx][info] keys added to .env.keys (DOTENV_KEY_PRODUCTION,DOTENV_KEY_PRODUCTION)
40
+
41
+ $ DOTENV_KEY='<dotenv_key_production>' dotenvx run -- node index.js
42
+ [dotenvx][info] loading env (1) from encrypted .env.vault
43
+ Hello production
44
+ \`\`\`
45
+ `
46
+ }
47
+
48
+ module.exports = {
49
+ run,
50
+ encrypt
51
+ }
@@ -10,7 +10,7 @@ const packageJson = require('./packageJson')
10
10
  const dotenvxFormat = printf(({ level, message, label, timestamp }) => {
11
11
  const formattedMessage = typeof message === 'object' ? JSON.stringify(message) : message
12
12
 
13
- return `[dotenvx@${packageJson.version}][${level.toUpperCase()}] ${formattedMessage}`
13
+ return `[dotenvx@${packageJson.version}][${level.toLowerCase()}] ${formattedMessage}`
14
14
  })
15
15
 
16
16
  const logger = createLogger({