envx-cli 1.2.4 → 1.3.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 +404 -83
- package/dist/commands/config.d.ts +3 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +276 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/copy.d.ts.map +1 -1
- package/dist/commands/copy.js +8 -7
- package/dist/commands/copy.js.map +1 -1
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +3 -2
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/decrypt.d.ts.map +1 -1
- package/dist/commands/decrypt.js +17 -4
- package/dist/commands/decrypt.js.map +1 -1
- package/dist/commands/encrypt.d.ts +4 -0
- package/dist/commands/encrypt.d.ts.map +1 -1
- package/dist/commands/encrypt.js +24 -4
- package/dist/commands/encrypt.js.map +1 -1
- package/dist/commands/interactive.d.ts.map +1 -1
- package/dist/commands/interactive.js +3 -2
- package/dist/commands/interactive.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +66 -16
- package/dist/index.js.map +1 -1
- package/dist/schemas/index.d.ts +14 -0
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +6 -1
- package/dist/schemas/index.js.map +1 -1
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +10 -0
- package/dist/types/index.js.map +1 -1
- package/dist/utils/file.d.ts +9 -2
- package/dist/utils/file.d.ts.map +1 -1
- package/dist/utils/file.js +75 -6
- package/dist/utils/file.js.map +1 -1
- package/dist/utils/interactive.d.ts +1 -1
- package/dist/utils/interactive.d.ts.map +1 -1
- package/dist/utils/interactive.js +7 -2
- package/dist/utils/interactive.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,19 +5,74 @@ Environment file encryption and management tool for secure development workflows
|
|
|
5
5
|
[](https://badge.fury.io/js/envx-cli)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
|
|
8
|
+
## Table of Contents
|
|
9
|
+
|
|
10
|
+
- [Overview](#overview)
|
|
11
|
+
- [Features](#features)
|
|
12
|
+
- [Prerequisites](#prerequisites)
|
|
13
|
+
- [Installation](#installation)
|
|
14
|
+
- [Quick Start](#quick-start)
|
|
15
|
+
- [Commands](#commands)
|
|
16
|
+
- [envx init](#envx-init)
|
|
17
|
+
- [envx create](#envx-create)
|
|
18
|
+
- [envx encrypt](#envx-encrypt)
|
|
19
|
+
- [envx decrypt](#envx-decrypt)
|
|
20
|
+
- [envx interactive](#envx-interactive)
|
|
21
|
+
- [envx list](#envx-list)
|
|
22
|
+
- [envx copy](#envx-copy)
|
|
23
|
+
- [envx status](#envx-status)
|
|
24
|
+
- [envx config](#envx-config)
|
|
25
|
+
- [Configuration](#configuration)
|
|
26
|
+
- [.envrc File](#envrc-file)
|
|
27
|
+
- [.envxrc File (Project Config)](#envxrc-file-project-config)
|
|
28
|
+
- [Secret Variable Naming](#secret-variable-naming)
|
|
29
|
+
- [Environment Filtering](#environment-filtering)
|
|
30
|
+
- [File Structure](#file-structure)
|
|
31
|
+
- [Workflow Examples](#workflow-examples)
|
|
32
|
+
- [Basic Workflow](#basic-workflow)
|
|
33
|
+
- [Deployment Workflow](#deployment-workflow)
|
|
34
|
+
- [Team Workflow](#team-workflow)
|
|
35
|
+
- [Multi-Service Management](#multi-service-management)
|
|
36
|
+
- [Batch Operations](#batch-operations)
|
|
37
|
+
- [Copy to .env Workflow](#copy-to-env-workflow)
|
|
38
|
+
- [Dry Run Workflow](#dry-run-workflow)
|
|
39
|
+
- [Security Best Practices](#security-best-practices)
|
|
40
|
+
- [Integration with Direnv](#integration-with-direnv)
|
|
41
|
+
- [Troubleshooting](#troubleshooting)
|
|
42
|
+
- [API Reference](#api-reference)
|
|
43
|
+
- [Environment Variables](#environment-variables)
|
|
44
|
+
- [Exit Codes](#exit-codes)
|
|
45
|
+
- [Testing](#testing)
|
|
46
|
+
- [Running Tests](#running-tests)
|
|
47
|
+
- [Testing Philosophy](#testing-philosophy)
|
|
48
|
+
- [Test Coverage](#test-coverage)
|
|
49
|
+
- [Test Structure](#test-structure)
|
|
50
|
+
- [Development](#development)
|
|
51
|
+
- [Building from Source](#building-from-source)
|
|
52
|
+
- [Architecture](#architecture)
|
|
53
|
+
- [Development Workflow](#development-workflow)
|
|
54
|
+
- [Contributing](#contributing)
|
|
55
|
+
- [Changelog](#changelog)
|
|
56
|
+
- [License](#license)
|
|
57
|
+
- [Support](#support)
|
|
58
|
+
|
|
8
59
|
## Overview
|
|
9
60
|
|
|
10
61
|
EnvX is a command-line tool that helps you securely manage environment files across different stages (development, staging, production) using GPG encryption. It provides a simple workflow for encrypting sensitive environment variables while maintaining ease of use for development teams.
|
|
11
62
|
|
|
12
63
|
## Features
|
|
13
64
|
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
65
|
+
- **GPG-based encryption** for maximum security
|
|
66
|
+
- **Stage-based management** (development, staging, production, etc.)
|
|
67
|
+
- **Interactive setup** with guided configuration
|
|
68
|
+
- **Batch operations** on multiple files and directories
|
|
69
|
+
- **Secret management** with `.envrc` integration
|
|
70
|
+
- **Project configuration** via `.envxrc` for per-project ignore patterns and environment tracking
|
|
71
|
+
- **Environment filtering** to auto-ignore non-secret files (example, sample, template)
|
|
72
|
+
- **Dry run mode** to preview operations without making changes
|
|
73
|
+
- **Config management** CLI for managing project settings without editing JSON
|
|
74
|
+
- **Beautiful CLI** with colored output and progress indicators
|
|
75
|
+
- **Best practices** enforcement and security recommendations
|
|
21
76
|
|
|
22
77
|
## Prerequisites
|
|
23
78
|
|
|
@@ -121,6 +176,21 @@ Initialize EnvX in a new project with guided setup.
|
|
|
121
176
|
envx init
|
|
122
177
|
```
|
|
123
178
|
|
|
179
|
+
The init wizard will:
|
|
180
|
+
|
|
181
|
+
1. Verify GPG is available
|
|
182
|
+
2. Discover existing environment files, auto-ignoring non-secret files (example, sample, template)
|
|
183
|
+
3. Let you select which environments to manage via checkbox prompt
|
|
184
|
+
4. Offer to add non-selected environments to the ignore list in `.envxrc`
|
|
185
|
+
5. Save your selected environments to `.envxrc`
|
|
186
|
+
6. Update `.gitignore` with recommended patterns
|
|
187
|
+
7. Optionally start interactive secret setup
|
|
188
|
+
8. Optionally encrypt your environment files immediately after setup
|
|
189
|
+
|
|
190
|
+
**Options:**
|
|
191
|
+
|
|
192
|
+
- `-c, --cwd <path>` - Working directory
|
|
193
|
+
|
|
124
194
|
### `envx create`
|
|
125
195
|
|
|
126
196
|
Create new environment files.
|
|
@@ -158,6 +228,9 @@ envx encrypt -e production
|
|
|
158
228
|
# Encrypt all environments at once
|
|
159
229
|
envx encrypt --all
|
|
160
230
|
|
|
231
|
+
# Preview what would be encrypted (no changes made)
|
|
232
|
+
envx encrypt -e production --dry-run
|
|
233
|
+
|
|
161
234
|
# Use custom secret from .envrc
|
|
162
235
|
envx encrypt -e production -s CUSTOM_SECRET
|
|
163
236
|
|
|
@@ -167,8 +240,8 @@ envx encrypt -e staging -i
|
|
|
167
240
|
# Encrypt all with specific passphrase
|
|
168
241
|
envx encrypt --all -p "your-passphrase"
|
|
169
242
|
|
|
170
|
-
#
|
|
171
|
-
envx encrypt -e
|
|
243
|
+
# Overwrite existing encrypted files
|
|
244
|
+
envx encrypt -e production --overwrite
|
|
172
245
|
```
|
|
173
246
|
|
|
174
247
|
**Options:**
|
|
@@ -178,6 +251,8 @@ envx encrypt -e development -p "your-passphrase"
|
|
|
178
251
|
- `-p, --passphrase <pass>` - Encryption passphrase
|
|
179
252
|
- `-s, --secret <secret>` - Secret variable name from .envrc
|
|
180
253
|
- `-i, --interactive` - Interactive file selection (disabled with --all)
|
|
254
|
+
- `--overwrite` - Overwrite existing encrypted files
|
|
255
|
+
- `--dry-run` - Show what would happen without making changes
|
|
181
256
|
- `-c, --cwd <path>` - Working directory
|
|
182
257
|
|
|
183
258
|
### `envx decrypt`
|
|
@@ -191,6 +266,9 @@ envx decrypt -e production
|
|
|
191
266
|
# Decrypt all environments at once
|
|
192
267
|
envx decrypt --all
|
|
193
268
|
|
|
269
|
+
# Preview what would be decrypted (no changes made)
|
|
270
|
+
envx decrypt -e production --dry-run
|
|
271
|
+
|
|
194
272
|
# Overwrite existing files without confirmation
|
|
195
273
|
envx decrypt -e development --overwrite
|
|
196
274
|
|
|
@@ -209,6 +287,7 @@ envx decrypt -e staging -i
|
|
|
209
287
|
- `-s, --secret <secret>` - Secret variable name from .envrc
|
|
210
288
|
- `-i, --interactive` - Interactive file selection (disabled with --all)
|
|
211
289
|
- `--overwrite` - Overwrite existing files without confirmation
|
|
290
|
+
- `--dry-run` - Show what would happen without making changes
|
|
212
291
|
- `-c, --cwd <path>` - Working directory
|
|
213
292
|
|
|
214
293
|
### `envx interactive`
|
|
@@ -234,7 +313,7 @@ envx interactive --generate
|
|
|
234
313
|
|
|
235
314
|
### `envx list`
|
|
236
315
|
|
|
237
|
-
List all environment files and their status.
|
|
316
|
+
List all environment files and their status. Automatically filters out non-secret environments (example, sample, template) based on your [ignore patterns](#environment-filtering).
|
|
238
317
|
|
|
239
318
|
```bash
|
|
240
319
|
# List all environment files
|
|
@@ -296,7 +375,7 @@ envx copy -e production --all --overwrite
|
|
|
296
375
|
|
|
297
376
|
### `envx status`
|
|
298
377
|
|
|
299
|
-
Show project encryption status and recommendations.
|
|
378
|
+
Show project encryption status and recommendations. Automatically filters out non-secret environments based on your [ignore patterns](#environment-filtering).
|
|
300
379
|
|
|
301
380
|
```bash
|
|
302
381
|
envx status
|
|
@@ -306,6 +385,213 @@ envx status
|
|
|
306
385
|
|
|
307
386
|
- `-c, --cwd <path>` - Working directory
|
|
308
387
|
|
|
388
|
+
### `envx config`
|
|
389
|
+
|
|
390
|
+
Manage project configuration stored in `.envxrc` without editing JSON manually.
|
|
391
|
+
|
|
392
|
+
#### `envx config show`
|
|
393
|
+
|
|
394
|
+
Display the current `.envxrc` configuration, showing both custom settings and defaults.
|
|
395
|
+
|
|
396
|
+
```bash
|
|
397
|
+
envx config show
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
#### `envx config ignore list`
|
|
401
|
+
|
|
402
|
+
List all current ignore patterns (from `.envxrc` or defaults).
|
|
403
|
+
|
|
404
|
+
```bash
|
|
405
|
+
envx config ignore list
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
#### `envx config ignore add <pattern>`
|
|
409
|
+
|
|
410
|
+
Add a pattern to the ignore list. Environments matching this pattern will be excluded from operations like `--all`, `list`, and `status`.
|
|
411
|
+
|
|
412
|
+
```bash
|
|
413
|
+
# Ignore the "test" environment
|
|
414
|
+
envx config ignore add test
|
|
415
|
+
|
|
416
|
+
# Ignore a custom environment name
|
|
417
|
+
envx config ignore add local-dev
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
#### `envx config ignore remove <pattern>`
|
|
421
|
+
|
|
422
|
+
Remove a pattern from the ignore list.
|
|
423
|
+
|
|
424
|
+
```bash
|
|
425
|
+
envx config ignore remove test
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
#### `envx config exclude list`
|
|
429
|
+
|
|
430
|
+
List all excluded directories (from `.envxrc` or defaults). These directories are skipped during environment file discovery, which is useful in monorepos and projects with build artifacts.
|
|
431
|
+
|
|
432
|
+
```bash
|
|
433
|
+
envx config exclude list
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
#### `envx config exclude add <dir>`
|
|
437
|
+
|
|
438
|
+
Add a directory to the exclusion list.
|
|
439
|
+
|
|
440
|
+
```bash
|
|
441
|
+
# Exclude Vercel build output
|
|
442
|
+
envx config exclude add .vercel
|
|
443
|
+
|
|
444
|
+
# Exclude a custom build directory
|
|
445
|
+
envx config exclude add out
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
#### `envx config exclude remove <dir>`
|
|
449
|
+
|
|
450
|
+
Remove a directory from the exclusion list.
|
|
451
|
+
|
|
452
|
+
```bash
|
|
453
|
+
envx config exclude remove build
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
#### `envx config reset`
|
|
457
|
+
|
|
458
|
+
Reset the configuration to defaults, removing all custom ignore patterns and directory exclusions.
|
|
459
|
+
|
|
460
|
+
```bash
|
|
461
|
+
envx config reset
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
## Configuration
|
|
465
|
+
|
|
466
|
+
### `.envrc` File
|
|
467
|
+
|
|
468
|
+
EnvX uses `.envrc` files to store encryption secrets. The format follows the direnv convention:
|
|
469
|
+
|
|
470
|
+
```bash
|
|
471
|
+
# Environment secrets generated by envx
|
|
472
|
+
export DEVELOPMENT_SECRET="your-development-secret"
|
|
473
|
+
export STAGING_SECRET="your-staging-secret"
|
|
474
|
+
export PRODUCTION_SECRET="your-production-secret"
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
### `.envxrc` File (Project Config)
|
|
478
|
+
|
|
479
|
+
EnvX supports a `.envxrc` JSON file in your project root for per-project configuration. This file is automatically managed by `envx init` and `envx config` commands.
|
|
480
|
+
|
|
481
|
+
```json
|
|
482
|
+
{
|
|
483
|
+
"ignore": ["example", "sample", "template", "local-dev"],
|
|
484
|
+
"environments": ["development", "staging", "production"],
|
|
485
|
+
"excludeDirs": ["node_modules", ".git", "dist", ".next", ".turbo", "build"]
|
|
486
|
+
}
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
**Fields:**
|
|
490
|
+
|
|
491
|
+
| Field | Type | Description |
|
|
492
|
+
| -------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
493
|
+
| `ignore` | `string[]` | Patterns to exclude from environment discovery. Environments whose names match any pattern (case-insensitive) are filtered from `--all`, `list`, and `status` operations. Defaults to `["example", "sample", "template"]` if not set. |
|
|
494
|
+
| `environments` | `string[]` | List of managed environments. Set during `envx init` based on your selection. |
|
|
495
|
+
| `excludeDirs` | `string[]` | Directories to exclude from file discovery. Prevents scanning into build artifacts and dependency directories. Defaults to `["node_modules", ".git", "dist", ".next", ".turbo", ".output", ".nuxt", ".cache", "build", "coverage", ".svelte-kit"]`. |
|
|
496
|
+
|
|
497
|
+
You can manage this file through the CLI:
|
|
498
|
+
|
|
499
|
+
```bash
|
|
500
|
+
# View current config
|
|
501
|
+
envx config show
|
|
502
|
+
|
|
503
|
+
# Add a custom ignore pattern
|
|
504
|
+
envx config ignore add test
|
|
505
|
+
|
|
506
|
+
# Remove a pattern
|
|
507
|
+
envx config ignore remove sample
|
|
508
|
+
|
|
509
|
+
# Add a directory exclusion
|
|
510
|
+
envx config exclude add .vercel
|
|
511
|
+
|
|
512
|
+
# Remove a directory exclusion
|
|
513
|
+
envx config exclude remove build
|
|
514
|
+
|
|
515
|
+
# Reset to defaults
|
|
516
|
+
envx config reset
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
Or edit `.envxrc` directly as JSON.
|
|
520
|
+
|
|
521
|
+
### Secret Variable Naming
|
|
522
|
+
|
|
523
|
+
EnvX follows the convention: `<STAGE>_SECRET`
|
|
524
|
+
|
|
525
|
+
Examples:
|
|
526
|
+
|
|
527
|
+
- `DEVELOPMENT_SECRET`
|
|
528
|
+
- `STAGING_SECRET`
|
|
529
|
+
- `PRODUCTION_SECRET`
|
|
530
|
+
- `LOCAL_SECRET`
|
|
531
|
+
|
|
532
|
+
### Environment Filtering
|
|
533
|
+
|
|
534
|
+
EnvX automatically filters non-secret environment files from discovery operations. By default, files matching `example`, `sample`, or `template` are excluded.
|
|
535
|
+
|
|
536
|
+
This filtering applies to:
|
|
537
|
+
|
|
538
|
+
- `envx encrypt --all` / `envx decrypt --all` (batch operations)
|
|
539
|
+
- `envx list` (environment listing)
|
|
540
|
+
- `envx status` (project status)
|
|
541
|
+
- `envx init` (environment discovery)
|
|
542
|
+
|
|
543
|
+
**How it works:**
|
|
544
|
+
|
|
545
|
+
1. If `.envxrc` exists with an `ignore` field, those patterns are used
|
|
546
|
+
2. If no `.envxrc` exists or `ignore` is not set, the defaults are used: `["example", "sample", "template"]`
|
|
547
|
+
3. Pattern matching is case-insensitive (`.env.Example` matches pattern `example`)
|
|
548
|
+
|
|
549
|
+
**Customizing filters:**
|
|
550
|
+
|
|
551
|
+
```bash
|
|
552
|
+
# Add a custom pattern
|
|
553
|
+
envx config ignore add test
|
|
554
|
+
|
|
555
|
+
# Remove a default pattern (to include it in operations)
|
|
556
|
+
envx config ignore remove template
|
|
557
|
+
|
|
558
|
+
# See current patterns
|
|
559
|
+
envx config ignore list
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
**Bypass filtering:** Pass an explicit empty ignore list programmatically via `findAllEnvironments(cwd, [])` to include all environments.
|
|
563
|
+
|
|
564
|
+
#### Directory Exclusion (Monorepo Support)
|
|
565
|
+
|
|
566
|
+
EnvX automatically excludes build artifact and dependency directories from file discovery. This prevents `.env.*` files duplicated inside `node_modules`, `.next`, `dist`, `.turbo`, and other directories from appearing as spurious results.
|
|
567
|
+
|
|
568
|
+
**Default excluded directories:** `node_modules`, `.git`, `dist`, `.next`, `.turbo`, `.output`, `.nuxt`, `.cache`, `build`, `coverage`, `.svelte-kit`
|
|
569
|
+
|
|
570
|
+
**Customizing exclusions:**
|
|
571
|
+
|
|
572
|
+
```bash
|
|
573
|
+
# View current exclusions
|
|
574
|
+
envx config exclude list
|
|
575
|
+
|
|
576
|
+
# Add a directory
|
|
577
|
+
envx config exclude add .vercel
|
|
578
|
+
|
|
579
|
+
# Remove a directory (e.g., to scan build output)
|
|
580
|
+
envx config exclude remove build
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
### File Structure
|
|
584
|
+
|
|
585
|
+
```
|
|
586
|
+
your-project/
|
|
587
|
+
├── .env.development # Unencrypted (local only)
|
|
588
|
+
├── .env.staging.gpg # Encrypted (committed)
|
|
589
|
+
├── .env.production.gpg # Encrypted (committed)
|
|
590
|
+
├── .envrc # Secrets (local only)
|
|
591
|
+
├── .envxrc # Project config (local only)
|
|
592
|
+
└── .gitignore # Excludes .env.* but allows *.gpg
|
|
593
|
+
```
|
|
594
|
+
|
|
309
595
|
## Workflow Examples
|
|
310
596
|
|
|
311
597
|
### Basic Workflow
|
|
@@ -458,11 +744,12 @@ envx decrypt --all --overwrite
|
|
|
458
744
|
|
|
459
745
|
**Benefits of using `--all`:**
|
|
460
746
|
|
|
461
|
-
-
|
|
462
|
-
-
|
|
463
|
-
-
|
|
464
|
-
-
|
|
465
|
-
-
|
|
747
|
+
- **Efficiency**: Process multiple environments in one command
|
|
748
|
+
- **Consistency**: Same passphrase/secret handling across all environments
|
|
749
|
+
- **Automation**: Perfect for CI/CD pipelines and scripts
|
|
750
|
+
- **Safety**: Each environment is processed independently - failures in one don't stop others
|
|
751
|
+
- **Reporting**: Comprehensive summary showing results for each environment
|
|
752
|
+
- **Filtering**: Automatically skips non-secret environments (example, sample, template)
|
|
466
753
|
|
|
467
754
|
**Key Features of `--all` Flag:**
|
|
468
755
|
|
|
@@ -490,67 +777,56 @@ envx copy -e production --overwrite
|
|
|
490
777
|
|
|
491
778
|
**Use cases for `envx copy`:**
|
|
492
779
|
|
|
493
|
-
-
|
|
494
|
-
-
|
|
495
|
-
-
|
|
496
|
-
-
|
|
497
|
-
-
|
|
498
|
-
-
|
|
499
|
-
-
|
|
780
|
+
- **Deployment**: Copy environment configuration to `.env` for application use
|
|
781
|
+
- **Environment Switching**: Quickly switch between different configurations
|
|
782
|
+
- **Local Development**: Use production/staging config locally for debugging
|
|
783
|
+
- **Docker/Containers**: Set up environment in containerized deployments
|
|
784
|
+
- **CI/CD**: Activate specific environments during pipeline stages
|
|
785
|
+
- **Multi-Service**: Manage environment files across multiple services from project root
|
|
786
|
+
- **Batch Operations**: Copy same environment to all services with one command
|
|
500
787
|
|
|
501
|
-
|
|
788
|
+
### Dry Run Workflow
|
|
502
789
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
EnvX uses `.envrc` files to store encryption secrets. The format follows the direnv convention:
|
|
790
|
+
Preview encrypt/decrypt operations before executing them:
|
|
506
791
|
|
|
507
792
|
```bash
|
|
508
|
-
#
|
|
509
|
-
|
|
510
|
-
export STAGING_SECRET="your-staging-secret"
|
|
511
|
-
export PRODUCTION_SECRET="your-production-secret"
|
|
512
|
-
```
|
|
793
|
+
# See what files would be encrypted
|
|
794
|
+
envx encrypt -e production --dry-run
|
|
513
795
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
EnvX follows the convention: `<STAGE>_SECRET`
|
|
796
|
+
# Preview batch encryption
|
|
797
|
+
envx encrypt --all -p "your-passphrase" --dry-run
|
|
517
798
|
|
|
518
|
-
|
|
799
|
+
# Preview decryption
|
|
800
|
+
envx decrypt -e production --dry-run
|
|
801
|
+
```
|
|
519
802
|
|
|
520
|
-
|
|
521
|
-
- `STAGING_SECRET`
|
|
522
|
-
- `PRODUCTION_SECRET`
|
|
523
|
-
- `LOCAL_SECRET`
|
|
803
|
+
Dry run mode shows:
|
|
524
804
|
|
|
525
|
-
|
|
805
|
+
- Which files would be processed
|
|
806
|
+
- The passphrase source (provided, `.envrc`, or interactive)
|
|
807
|
+
- Total file count
|
|
526
808
|
|
|
527
|
-
|
|
528
|
-
your-project/
|
|
529
|
-
├── .env.development # Unencrypted (local only)
|
|
530
|
-
├── .env.staging.gpg # Encrypted (committed)
|
|
531
|
-
├── .env.production.gpg # Encrypted (committed)
|
|
532
|
-
├── .envrc # Secrets (local only)
|
|
533
|
-
└── .gitignore # Excludes .env.* but allows *.gpg
|
|
534
|
-
```
|
|
809
|
+
No files are created, modified, or deleted during a dry run.
|
|
535
810
|
|
|
536
811
|
## Security Best Practices
|
|
537
812
|
|
|
538
|
-
###
|
|
813
|
+
### Do's
|
|
539
814
|
|
|
540
|
-
-
|
|
541
|
-
-
|
|
542
|
-
-
|
|
543
|
-
-
|
|
544
|
-
-
|
|
545
|
-
-
|
|
815
|
+
- Always encrypt production and staging environment files
|
|
816
|
+
- Commit encrypted `.gpg` files to version control
|
|
817
|
+
- Add `.envrc` and `.envxrc` to your `.gitignore`
|
|
818
|
+
- Use strong, unique secrets for each environment
|
|
819
|
+
- Regularly rotate encryption secrets
|
|
820
|
+
- Use `envx status` to check your security posture
|
|
821
|
+
- Use `--dry-run` to preview operations before executing
|
|
546
822
|
|
|
547
|
-
###
|
|
823
|
+
### Don'ts
|
|
548
824
|
|
|
549
|
-
-
|
|
550
|
-
-
|
|
551
|
-
-
|
|
552
|
-
-
|
|
553
|
-
-
|
|
825
|
+
- Never commit unencrypted `.env.*` files (except templates)
|
|
826
|
+
- Don't commit `.envrc` or `.envxrc` files to version control
|
|
827
|
+
- Don't use weak or predictable passphrases
|
|
828
|
+
- Don't share secrets through insecure channels
|
|
829
|
+
- Don't leave decrypted files in production environments
|
|
554
830
|
|
|
555
831
|
### Recommended `.gitignore`
|
|
556
832
|
|
|
@@ -561,8 +837,9 @@ your-project/
|
|
|
561
837
|
!.env.template
|
|
562
838
|
!*.gpg
|
|
563
839
|
|
|
564
|
-
# EnvX secrets
|
|
840
|
+
# EnvX secrets and config
|
|
565
841
|
.envrc
|
|
842
|
+
.envxrc
|
|
566
843
|
```
|
|
567
844
|
|
|
568
845
|
## Integration with Direnv
|
|
@@ -655,15 +932,18 @@ EnvX respects the following environment variables:
|
|
|
655
932
|
|
|
656
933
|
### Exit Codes
|
|
657
934
|
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
935
|
+
| Code | Constant | Description |
|
|
936
|
+
| ---- | ---------------- | -------------------------------- |
|
|
937
|
+
| `0` | `SUCCESS` | Operation completed successfully |
|
|
938
|
+
| `1` | `GENERAL_ERROR` | General error |
|
|
939
|
+
| `2` | `INVALID_ARGS` | Invalid arguments provided |
|
|
940
|
+
| `3` | `FILE_ERROR` | File operation failed |
|
|
941
|
+
| `4` | `GPG_ERROR` | GPG operation failed |
|
|
942
|
+
| `5` | `USER_CANCELLED` | Operation cancelled by user |
|
|
663
943
|
|
|
664
944
|
## Testing
|
|
665
945
|
|
|
666
|
-
EnvX includes a
|
|
946
|
+
EnvX includes a comprehensive test suite covering core functionality, configuration management, and real-world CLI usage scenarios.
|
|
667
947
|
|
|
668
948
|
### Running Tests
|
|
669
949
|
|
|
@@ -688,26 +968,32 @@ npm run test:watch
|
|
|
688
968
|
|
|
689
969
|
The test suite prioritizes **essential functionality** over comprehensive coverage:
|
|
690
970
|
|
|
691
|
-
-
|
|
692
|
-
-
|
|
693
|
-
-
|
|
694
|
-
-
|
|
695
|
-
- ❌ **Complex mocking** - Simplified approach focusing on actual behavior
|
|
971
|
+
- **Core business logic** - Command validation, file utilities, path manipulation
|
|
972
|
+
- **Configuration management** - `.envxrc` read/write/merge, ignore patterns, defaults
|
|
973
|
+
- **Real CLI scenarios** - Actual command execution in various environments
|
|
974
|
+
- **Critical workflows** - User-facing functionality that must work reliably
|
|
696
975
|
|
|
697
976
|
### Test Coverage
|
|
698
977
|
|
|
699
|
-
**Current Status**:
|
|
978
|
+
**Current Status**: 181 tests passing across 7 test suites
|
|
700
979
|
|
|
701
|
-
- **Core Tests**:
|
|
980
|
+
- **Core Tests**: 165 tests covering essential functionality
|
|
702
981
|
- Schema validation: 25 tests (command input validation)
|
|
703
|
-
- File utilities: 39 tests (path manipulation, secret generation)
|
|
982
|
+
- File utilities: 39 tests (path manipulation, secret generation, gitignore)
|
|
704
983
|
- Command logic: 25 tests (workflow patterns and decision logic)
|
|
705
984
|
- All-flag functionality: 15 tests (batch operations, error handling)
|
|
985
|
+
- EnvxrcConfig infrastructure: 23 tests (read/write/merge, ignore patterns, filtering)
|
|
986
|
+
- Config command: 7 tests (show, add, remove, reset operations)
|
|
987
|
+
- Copy command: 31 tests (single/multi-directory, encrypted/unencrypted)
|
|
706
988
|
|
|
707
989
|
- **Integration Tests**: 16 tests covering real CLI usage
|
|
708
990
|
- Help/version commands
|
|
709
991
|
- Create command functionality
|
|
710
|
-
-
|
|
992
|
+
- Init command validation
|
|
993
|
+
- Config subcommand (show, ignore, reset)
|
|
994
|
+
- Dry run flag (encrypt/decrypt)
|
|
995
|
+
- Copy `--all` flag
|
|
996
|
+
- Environment filtering (list, status)
|
|
711
997
|
- Error handling scenarios
|
|
712
998
|
- Environment validation
|
|
713
999
|
|
|
@@ -717,9 +1003,11 @@ The test suite prioritizes **essential functionality** over comprehensive covera
|
|
|
717
1003
|
__tests__/
|
|
718
1004
|
├── core/ # Essential functionality tests
|
|
719
1005
|
│ ├── schemas.test.ts # Input validation for all commands
|
|
720
|
-
│ ├── file.test.ts # File utilities
|
|
1006
|
+
│ ├── file.test.ts # File utilities, path manipulation, gitignore
|
|
721
1007
|
│ ├── commands.test.ts # Command workflow logic patterns
|
|
722
|
-
│
|
|
1008
|
+
│ ├── all-flag.test.ts # Batch operations and --all flag functionality
|
|
1009
|
+
│ ├── envxrc.test.ts # .envxrc config read/write/merge/filtering
|
|
1010
|
+
│ └── config.test.ts # Config command operations
|
|
723
1011
|
└── integration/ # End-to-end CLI tests
|
|
724
1012
|
└── cli.test.ts # Real CLI execution scenarios
|
|
725
1013
|
```
|
|
@@ -738,6 +1026,36 @@ npm run build
|
|
|
738
1026
|
npm link
|
|
739
1027
|
```
|
|
740
1028
|
|
|
1029
|
+
### Architecture
|
|
1030
|
+
|
|
1031
|
+
```
|
|
1032
|
+
src/
|
|
1033
|
+
├── index.ts # Entry point, CLI framework, inline commands
|
|
1034
|
+
├── commands/ # Command implementations
|
|
1035
|
+
│ ├── config.ts # envx config subcommand
|
|
1036
|
+
│ ├── copy.ts # envx copy
|
|
1037
|
+
│ ├── create.ts # envx create
|
|
1038
|
+
│ ├── decrypt.ts # envx decrypt
|
|
1039
|
+
│ ├── encrypt.ts # envx encrypt
|
|
1040
|
+
│ └── interactive.ts # envx interactive
|
|
1041
|
+
├── schemas/
|
|
1042
|
+
│ └── index.ts # Zod validation schemas
|
|
1043
|
+
├── types/
|
|
1044
|
+
│ └── index.ts # TypeScript interfaces and enums
|
|
1045
|
+
└── utils/
|
|
1046
|
+
├── exec.ts # GPG operations, CLI output (ExecUtils, CliUtils)
|
|
1047
|
+
├── file.ts # File discovery, .envrc/.envxrc, gitignore (FileUtils)
|
|
1048
|
+
└── interactive.ts # User prompts via inquirer (InteractiveUtils)
|
|
1049
|
+
```
|
|
1050
|
+
|
|
1051
|
+
**Key patterns:**
|
|
1052
|
+
|
|
1053
|
+
- Each command file exports `createXxxCommand()` (Commander command) and `executeXxx()` (core logic)
|
|
1054
|
+
- All utility classes use static methods, no instances
|
|
1055
|
+
- Zod schemas validate all command inputs; `--all` dynamically alters schema requirements
|
|
1056
|
+
- Configuration resolution: `--passphrase` flag > `.envrc` file > interactive prompt
|
|
1057
|
+
- Working directory: `--cwd` flag > `process.cwd()`
|
|
1058
|
+
|
|
741
1059
|
### Development Workflow
|
|
742
1060
|
|
|
743
1061
|
```bash
|
|
@@ -749,6 +1067,9 @@ npm run test:watch
|
|
|
749
1067
|
|
|
750
1068
|
# Build and test
|
|
751
1069
|
npm run build && npm test
|
|
1070
|
+
|
|
1071
|
+
# Lint and format
|
|
1072
|
+
npm run lint:fix && npm run format
|
|
752
1073
|
```
|
|
753
1074
|
|
|
754
1075
|
### Contributing
|
|
@@ -778,9 +1099,9 @@ MIT © [rahulretnan](https://github.com/rahulretnan)
|
|
|
778
1099
|
|
|
779
1100
|
## Support
|
|
780
1101
|
|
|
781
|
-
-
|
|
782
|
-
-
|
|
783
|
-
-
|
|
1102
|
+
- [Issues](https://github.com/rahulretnan/envx-cli/issues)
|
|
1103
|
+
- [Discussions](https://github.com/rahulretnan/envx-cli/discussions)
|
|
1104
|
+
- Email: hi@rahulretnan.me
|
|
784
1105
|
|
|
785
1106
|
---
|
|
786
1107
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,eAAO,MAAM,mBAAmB,QAAO,OAoItC,CAAC"}
|