@dotenc/cli 0.3.1 → 0.3.3
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 +125 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# 
|
|
2
|
+
🔐 Secure, encrypted environment variables that live in your codebase
|
|
3
|
+
|
|
4
|
+
## Features
|
|
5
|
+
|
|
6
|
+
- 🔒 Uses the battle-tested AES-256-GCM encryption algorithm
|
|
7
|
+
- 🔑 Keys can be exported anytime - no vendor lock-in
|
|
8
|
+
- 🚀 Secure command running with on-the-fly decryption
|
|
9
|
+
- ✍️ Easy and secure environment variable editing
|
|
10
|
+
- 🌍 Supports multiple and extensible environments
|
|
11
|
+
- 🔄 Offers a simplified key rotation process
|
|
12
|
+
|
|
13
|
+
## How It Works
|
|
14
|
+
|
|
15
|
+
1. Environment variables are encrypted using a secure key
|
|
16
|
+
2. Encrypted files (`.env.*.enc`) are committed to your repository
|
|
17
|
+
3. Keys are stored securely and not committed to the repository
|
|
18
|
+
4. The local, git-ignored `.env` file can be used for development
|
|
19
|
+
5. When running commands, variables are decrypted on-the-fly
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install -g @dotenc/cli
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Initialize a New Environment
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
dotenc init [environment]
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
This will:
|
|
36
|
+
1. Create a new encrypted environment file (`.env.[environment].enc`)
|
|
37
|
+
2. Set up a local `.env` file for development
|
|
38
|
+
3. Create a `dotenc.json` configuration file
|
|
39
|
+
|
|
40
|
+
### Edit an Environment
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
dotenc edit [environment]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Opens your system's default editor to modify the specified environment. To set a custom editor, use the `dotenc config editor` command. It will take precedence over your system's default editor.
|
|
47
|
+
|
|
48
|
+
Example:
|
|
49
|
+
```bash
|
|
50
|
+
dotenc config editor vim
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Run Commands on an Environment
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
dotenc run --env <environment> <command> [...args]
|
|
57
|
+
# or
|
|
58
|
+
dotenc run -e <environment> <command> [...args]
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Example:
|
|
62
|
+
```bash
|
|
63
|
+
dotenc run -e production node app.js
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
You can also specify multiple environments:
|
|
67
|
+
```bash
|
|
68
|
+
dotenc run -e base,production node app.js
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
In the example above, `production` will override any variables also present in `global`.
|
|
72
|
+
|
|
73
|
+
### Key management
|
|
74
|
+
|
|
75
|
+
To import a key into your machine, use the `key import` command:
|
|
76
|
+
```bash
|
|
77
|
+
dotenc key import <environment> <key>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
To export a key from your machine, use the `key export` command:
|
|
81
|
+
```bash
|
|
82
|
+
dotenc key export <environment>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
To rotate a key, use the `key rotate` command:
|
|
86
|
+
```bash
|
|
87
|
+
dotenc key rotate <environment>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Use Cases
|
|
91
|
+
|
|
92
|
+
For convenience, you can setup your `package.json` file like this:
|
|
93
|
+
```jsonc
|
|
94
|
+
// ...
|
|
95
|
+
"scripts": {
|
|
96
|
+
"dev": "dotenc run -e development tsx src/app.ts",
|
|
97
|
+
"start": "dotenc run -e production node dist/app.js",
|
|
98
|
+
"test": "dotenc run -e test vitest"
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Alternatively, the `DOTENC_ENV` variable can be used to set the environment, so the `-e` option can be omitted. For example:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
export DOTENC_ENV="production"
|
|
106
|
+
dotenc run node app.js
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Also, if a key is not present in your machine, you can use the `DOTENC_KEY` variable to decrypt an environment:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
DOTENC_KEY=<prod_key> dotenc run -e production node app.js
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
This can be useful for CI and automated platforms like Netlify and Vercel. Just export your keys and set the `DOTENC_KEY` variable in each environment.
|
|
116
|
+
|
|
117
|
+
The `DOTENC_KEY` variable also works with multiple environments:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
DOTENC_KEY=<base_key>,<prod_key> dotenc run -e base,production node app.js
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
MIT
|