@dotenvx/dotenvx
Advanced tools
Comparing version 0.6.4 to 0.6.5
{ | ||
"version": "0.6.4", | ||
"version": "0.6.5", | ||
"name": "@dotenvx/dotenvx", | ||
@@ -4,0 +4,0 @@ "description": "a better dotenv–from the creator of `dotenv`", |
154
README.md
@@ -5,5 +5,5 @@ ![dotenvx](https://dotenvx.com/better-banner.png) | ||
* [run anywhere](#run-anywhere) (cross-platform) | ||
* [multi-environment](#multiple-environments) | ||
* [encrypted envs](#encryption) | ||
* run anywhere (cross-platform) | ||
* multi-environment | ||
* encrypted envs | ||
@@ -67,2 +67,12 @@ | ||
</details> | ||
* <details><summary>Go 🐹</summary><br> | ||
```sh | ||
$ echo "HELLO=World" > .env && echo 'package main; import ("fmt"; "os"); func main() { fmt.Printf("Hello %s\n", os.Getenv("HELLO")) }' > main.go | ||
$ dotenvx run -- go run main.go | ||
Hello World | ||
``` | ||
</details> | ||
* <details><summary>Rust 🦀</summary><br> | ||
@@ -174,3 +184,3 @@ | ||
[dotenvx][INFO] injecting 1 environment variable from .env | ||
[dotenvx][info] loading env (1) from .env | ||
Hello World | ||
@@ -198,5 +208,7 @@ ``` | ||
```sh | ||
$ echo "HELLO=production" > .env.production && echo "console.log('Hello ' + process.env.HELLO)" > index.js | ||
$ echo "HELLO=production" > .env.production | ||
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js | ||
$ dotenvx run --env-file=.env.production -- node index.js | ||
[dotenvx][info] loading env (1) from .env.production | ||
Hello production | ||
@@ -216,2 +228,3 @@ > ^^ | ||
$ dotenvx run --env-file=.env.local --env-file=.env -- node index.js | ||
[dotenvx][info] loading env (1) from .env.local,.env | ||
Hello local | ||
@@ -230,2 +243,3 @@ ``` | ||
$ dotenvx run --env-file=.env.local --env-file=.env --overload -- node index.js | ||
[dotenvx][info] loading env (1) from .env.local,.env | ||
Hello World | ||
@@ -240,5 +254,5 @@ ``` | ||
$ dotenvx run --env-file=.env.production --verbose -- node index.js | ||
[dotenvx][VERBOSE] injecting env from /path/to/.env.production | ||
[dotenvx][VERBOSE] HELLO set | ||
[dotenvx][INFO] injecting 1 environment variable from .env.production | ||
[dotenvx][verbose] injecting env from /path/to/.env.production | ||
[dotenvx][verbose] HELLO set | ||
[dotenvx][info] loading env (1) from .env.production | ||
Hello production | ||
@@ -253,12 +267,12 @@ ``` | ||
$ dotenvx run --env-file=.env.production --debug -- node index.js | ||
[dotenvx][DEBUG] configuring options | ||
[dotenvx][DEBUG] {"envFile":[".env.production"]} | ||
[dotenvx][VERBOSE] injecting env from /path/to/.env.production | ||
[dotenvx][DEBUG] reading env from /path/to/.env.production | ||
[dotenvx][DEBUG] parsing env from /path/to/.env.production | ||
[dotenvx][DEBUG] {"HELLO":"production"} | ||
[dotenvx][DEBUG] writing env from /path/to/.env.production | ||
[dotenvx][VERBOSE] HELLO set | ||
[dotenvx][DEBUG] HELLO set to production | ||
[dotenvx][INFO] injecting 1 environment variable from .env.production | ||
[dotenvx][debug] configuring options | ||
[dotenvx][debug] {"envFile":[".env.production"]} | ||
[dotenvx][verbose] injecting env from /path/to/.env.production | ||
[dotenvx][debug] reading env from /path/to/.env.production | ||
[dotenvx][debug] parsing env from /path/to/.env.production | ||
[dotenvx][debug] {"HELLO":"production"} | ||
[dotenvx][debug] writing env from /path/to/.env.production | ||
[dotenvx][verbose] HELLO set | ||
[dotenvx][debug] HELLO set to production | ||
[dotenvx][info] loading env (1) from .env.production | ||
Hello production | ||
@@ -280,20 +294,4 @@ ``` | ||
$ dotenvx encrypt | ||
[dotenvx][INFO] encrypted .env,.env.production to .env.vault | ||
[dotenvx][INFO] | ||
[dotenvx][INFO] try it out: | ||
[dotenvx][INFO] | ||
[dotenvx][INFO] DOTENV_KEY='<DOTENV_KEY_ENVIRONMENT>' dotenvx run -- node index.js | ||
[dotenvx][INFO] | ||
[dotenvx][INFO] next: | ||
[dotenvx][INFO] | ||
[dotenvx][INFO] 1. commit .env.vault safely to code | ||
[dotenvx][INFO] 2. set DOTENV_KEY on server (or ci) | ||
[dotenvx][INFO] 3. push your code | ||
[dotenvx][INFO] | ||
[dotenvx][INFO] tips: | ||
[dotenvx][INFO] | ||
[dotenvx][INFO] * .env.keys file holds your decryption DOTENV_KEYs | ||
[dotenvx][INFO] * DO NOT commit .env.keys to code | ||
[dotenvx][INFO] * share .env.keys file over secure channels only | ||
> :-] | ||
[dotenvx][info] encrypted to .env.vault (.env,.env.production) | ||
[dotenvx][info] key added to .env.keys (DOTENV_KEY_PRODUCTION) | ||
``` | ||
@@ -306,7 +304,6 @@ | ||
```sh | ||
$ DOTENV_KEY='dotenv://:key_abc123@dotenvx.com/vault/.env.vault?environment=production' dotenvx run -- node index.js | ||
[dotenvx][INFO] injecting 1 environment variable from encrypted .env.vault | ||
$ DOTENV_KEY='<dotenv_key_production>' dotenvx run -- node index.js | ||
[dotenvx][info] loading env (1) from encrypted .env.vault | ||
Hello production | ||
> :-] | ||
^ :-] | ||
``` | ||
@@ -415,78 +412,7 @@ | ||
--- | ||
## Guides | ||
## Usage | ||
* [dotenvx/docs](https://dotenvx.com/docs) | ||
* [quickstart guide](https://dotenvx.com/docs/quickstart) | ||
### Guide | ||
Begin by creating a simple 'hello world' program. | ||
```js | ||
// index.js | ||
console.log(`Hello ${process.env.HELLO}`) | ||
``` | ||
Run it. | ||
```js | ||
$ node index.js | ||
Hello undefined | ||
``` | ||
Run it with `dotenvx`. | ||
```sh | ||
$ dotenvx run -- node index.js | ||
[dotenvx][WARN] ENOENT: no such file or directory, open '/../../.env' | ||
Hello undefined | ||
``` | ||
It warns you when there is no `.env` file (pass the `--quiet` flag to suppress these warnings). | ||
Create the `.env` file. | ||
```ini | ||
# env | ||
JELLO="World" | ||
``` | ||
Run it again. | ||
```sh | ||
$ dotenvx run -- node index.js | ||
[dotenvx][INFO] injecting 0 environment variables from .env | ||
Hello undefined | ||
``` | ||
Hrm, still undefined. Pass the `--debug` flag to debug the issue. I'll give you a hint: 🍮 | ||
```sh | ||
$ dotenvx run --debug -- node index.js | ||
[dotenvx][VERBOSE] Loading env from /../../.env | ||
[dotenvx][DEBUG] Reading env from /../../.env | ||
[dotenvx][DEBUG] Parsing env from /../../.env | ||
[dotenvx][DEBUG] {"JELLO":"World"} | ||
# Oops, HELLO not JELLO ^^ | ||
``` | ||
Fix your `.env` file. | ||
```ini | ||
# .env | ||
HELLO="World" | ||
``` | ||
One last time. [Le tired](https://youtu.be/kCpjgl2baLs?t=45). | ||
```sh | ||
$ dotenvx run -- node index.js | ||
[dotenvx][INFO] injecting 1 environment variable from .env | ||
Hello World | ||
``` | ||
🎉 It worked! | ||
| ||
## Contributing | ||
@@ -493,0 +419,0 @@ |
@@ -56,3 +56,3 @@ #!/usr/bin/env node | ||
program.command('run') | ||
.description('inject env variables into your application process') | ||
.description('load env into your application process') | ||
.option('-f, --env-file <paths...>', 'path(s) to your env file(s)', '.env') | ||
@@ -72,3 +72,3 @@ .option('-o, --overload', 'override existing env variables') | ||
} else { | ||
logger.verbose(`injecting encrypted env from ${filepath}`) | ||
logger.verbose(`loading env from encrypted ${filepath}`) | ||
@@ -117,3 +117,3 @@ try { | ||
logger.info(`injecting ${result.written.size} environment ${helpers.pluralize('variable', result.written.size)} from encrypted .env.vault`) | ||
logger.info(`loading env (${result.written.size}) from encrypted .env.vault`) | ||
} catch (e) { | ||
@@ -136,3 +136,3 @@ logger.error(e) | ||
logger.verbose(`injecting env from ${filepath}`) | ||
logger.verbose(`loading env from ${filepath}`) | ||
@@ -157,3 +157,3 @@ try { | ||
if (readableFilepaths.size > 0) { | ||
logger.info(`injecting ${written.size} environment ${helpers.pluralize('variable', written.size)} from ${[...readableFilepaths]}`) | ||
logger.info(`loading env (${written.size}) from ${[...readableFilepaths]}`) | ||
} | ||
@@ -188,2 +188,4 @@ } | ||
const addedKeys = new Set() | ||
try { | ||
@@ -212,2 +214,4 @@ logger.verbose(`generating .env.keys from ${optionEnvFile}`) | ||
dotenvKeys[key] = value | ||
addedKeys.add(key) // for info logging to user | ||
} else { | ||
@@ -279,21 +283,24 @@ logger.verbose(`existing ${key}`) | ||
logger.info(`encrypted ${optionEnvFile} to .env.vault`) | ||
logger.info('') | ||
logger.info('try it out:') | ||
logger.info('') | ||
logger.info(' DOTENV_KEY=\'<DOTENV_KEY_ENVIRONMENT>\' dotenvx run -- node index.js') | ||
logger.info('') | ||
logger.info('next:') | ||
logger.info('') | ||
logger.info(' 1. commit .env.vault safely to code') | ||
logger.info(' 2. set DOTENV_KEY on server (or ci)') | ||
logger.info(' 3. push your code') | ||
logger.info('') | ||
logger.info('tips:') | ||
logger.info('') | ||
logger.info(' * .env.keys file holds your decryption DOTENV_KEYs') | ||
logger.info(' * DO NOT commit .env.keys to code') | ||
logger.info(' * share .env.keys file over secure channels only') | ||
logger.info(`encrypted to .env.vault (${optionEnvFile})`) | ||
if (addedKeys.size > 0) { | ||
logger.info(`${helpers.pluralize('key', addedKeys.size)} added to .env.keys (${[...addedKeys]})`) | ||
} | ||
logger.verbose('') | ||
logger.verbose('try it out:') | ||
logger.verbose('') | ||
logger.verbose(' DOTENV_KEY=\'<DOTENV_KEY_ENVIRONMENT>\' dotenvx run -- node index.js') | ||
logger.verbose('') | ||
logger.verbose('next:') | ||
logger.verbose('') | ||
logger.verbose(' 1. commit .env.vault safely to code') | ||
logger.verbose(' 2. set DOTENV_KEY on server (or ci)') | ||
logger.verbose(' 3. push your code') | ||
logger.verbose('') | ||
logger.verbose('tips:') | ||
logger.verbose('') | ||
logger.verbose(' * .env.keys file holds your decryption DOTENV_KEYs') | ||
logger.verbose(' * DO NOT commit .env.keys to code') | ||
logger.verbose(' * share .env.keys file over secure channels only') | ||
}) | ||
program.parse(process.argv) |
@@ -13,3 +13,3 @@ const winston = require('winston') | ||
return `[dotenvx@${packageJson.version}][${level.toUpperCase()}] ${formattedMessage}` | ||
return `[dotenvx@${packageJson.version}][${level.toLowerCase()}] ${formattedMessage}` | ||
}) | ||
@@ -16,0 +16,0 @@ |
510
26980
413