envx-cli 1.0.0

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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +550 -0
  3. package/dist/commands/create.d.ts +3 -0
  4. package/dist/commands/create.d.ts.map +1 -0
  5. package/dist/commands/create.js +281 -0
  6. package/dist/commands/create.js.map +1 -0
  7. package/dist/commands/decrypt.d.ts +3 -0
  8. package/dist/commands/decrypt.d.ts.map +1 -0
  9. package/dist/commands/decrypt.js +206 -0
  10. package/dist/commands/decrypt.js.map +1 -0
  11. package/dist/commands/encrypt.d.ts +3 -0
  12. package/dist/commands/encrypt.d.ts.map +1 -0
  13. package/dist/commands/encrypt.js +194 -0
  14. package/dist/commands/encrypt.js.map +1 -0
  15. package/dist/commands/interactive.d.ts +4 -0
  16. package/dist/commands/interactive.d.ts.map +1 -0
  17. package/dist/commands/interactive.js +218 -0
  18. package/dist/commands/interactive.js.map +1 -0
  19. package/dist/index.d.ts +5 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +299 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/schemas/index.d.ts +167 -0
  24. package/dist/schemas/index.d.ts.map +1 -0
  25. package/dist/schemas/index.js +76 -0
  26. package/dist/schemas/index.js.map +1 -0
  27. package/dist/types/index.d.ts +64 -0
  28. package/dist/types/index.d.ts.map +1 -0
  29. package/dist/types/index.js +3 -0
  30. package/dist/types/index.js.map +1 -0
  31. package/dist/utils/exec.d.ts +32 -0
  32. package/dist/utils/exec.d.ts.map +1 -0
  33. package/dist/utils/exec.js +208 -0
  34. package/dist/utils/exec.js.map +1 -0
  35. package/dist/utils/file.d.ts +22 -0
  36. package/dist/utils/file.d.ts.map +1 -0
  37. package/dist/utils/file.js +200 -0
  38. package/dist/utils/file.js.map +1 -0
  39. package/dist/utils/interactive.d.ts +18 -0
  40. package/dist/utils/interactive.d.ts.map +1 -0
  41. package/dist/utils/interactive.js +365 -0
  42. package/dist/utils/interactive.js.map +1 -0
  43. package/package.json +74 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 EnvX Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,550 @@
1
+ # EnvX 🔐
2
+
3
+ Environment file encryption and management tool for secure development workflows.
4
+
5
+ [![npm version](https://badge.fury.io/js/envx-cli.svg)](https://badge.fury.io/js/envx-cli)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Overview
9
+
10
+ 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
+
12
+ ## Features
13
+
14
+ - 🔒 **GPG-based encryption** for maximum security
15
+ - 🎯 **Stage-based management** (development, staging, production, etc.)
16
+ - 🚀 **Interactive setup** with guided configuration
17
+ - 📁 **Batch operations** on multiple files and directories
18
+ - 🔑 **Secret management** with `.envrc` integration
19
+ - 🎨 **Beautiful CLI** with colored output and progress indicators
20
+ - 🛡️ **Best practices** enforcement and security recommendations
21
+
22
+ ## Prerequisites
23
+
24
+ Before using EnvX, ensure you have:
25
+
26
+ - **Node.js** >= 14.0.0
27
+ - **GPG** (GNU Privacy Guard) installed and configured
28
+
29
+ ### Installing GPG
30
+
31
+ #### macOS
32
+ ```bash
33
+ brew install gnupg
34
+ ```
35
+
36
+ #### Ubuntu/Debian
37
+ ```bash
38
+ sudo apt-get install gnupg
39
+ ```
40
+
41
+ #### Windows
42
+ Download from [https://gnupg.org/download/](https://gnupg.org/download/)
43
+
44
+ #### Verify Installation
45
+ ```bash
46
+ gpg --version
47
+ ```
48
+
49
+ ## Installation
50
+
51
+ ### Global Installation (Recommended)
52
+ ```bash
53
+ npm install -g envx
54
+ ```
55
+
56
+ ### Local Installation
57
+ ```bash
58
+ npm install envx
59
+ npx envx --help
60
+ ```
61
+
62
+ ## Quick Start
63
+
64
+ 1. **Initialize EnvX in your project:**
65
+ ```bash
66
+ envx init
67
+ ```
68
+
69
+ 2. **Create environment files:**
70
+ ```bash
71
+ envx create -e development
72
+ envx create -e production
73
+ ```
74
+
75
+ 3. **Set up secrets for encryption:**
76
+ ```bash
77
+ envx interactive
78
+ ```
79
+
80
+ 4. **Encrypt your environment files:**
81
+ ```bash
82
+ envx encrypt -e production
83
+ ```
84
+
85
+ 5. **Commit encrypted files to git:**
86
+ ```bash
87
+ git add *.gpg
88
+ git commit -m "Add encrypted environment files"
89
+ ```
90
+
91
+ 6. **Decrypt when needed:**
92
+ ```bash
93
+ envx decrypt -e production
94
+ ```
95
+
96
+ ## Commands
97
+
98
+ ### `envx init`
99
+ Initialize EnvX in a new project with guided setup.
100
+
101
+ ```bash
102
+ envx init
103
+ ```
104
+
105
+ ### `envx create`
106
+ Create new environment files.
107
+
108
+ ```bash
109
+ # Create a single environment file
110
+ envx create -e development
111
+
112
+ # Interactive mode for multiple environments
113
+ envx create -i
114
+
115
+ # Use a template file
116
+ envx create -e production -t .env.example
117
+
118
+ # Overwrite existing files
119
+ envx create -e staging --overwrite
120
+ ```
121
+
122
+ **Options:**
123
+ - `-e, --environment <env>` - Environment name
124
+ - `-t, --template <path>` - Template file path
125
+ - `-i, --interactive` - Interactive mode
126
+ - `--overwrite` - Overwrite existing files
127
+ - `-c, --cwd <path>` - Working directory
128
+
129
+ ### `envx encrypt`
130
+ Encrypt environment files using GPG.
131
+
132
+ ```bash
133
+ # Encrypt specific environment
134
+ envx encrypt -e production
135
+
136
+ # Use custom secret from .envrc
137
+ envx encrypt -e production -s CUSTOM_SECRET
138
+
139
+ # Interactive file selection
140
+ envx encrypt -e staging -i
141
+
142
+ # Specify passphrase directly (not recommended)
143
+ envx encrypt -e development -p "your-passphrase"
144
+ ```
145
+
146
+ **Options:**
147
+ - `-e, --environment <env>` - Environment name (required)
148
+ - `-p, --passphrase <pass>` - Encryption passphrase
149
+ - `-s, --secret <secret>` - Secret variable name from .envrc
150
+ - `-i, --interactive` - Interactive file selection
151
+ - `-c, --cwd <path>` - Working directory
152
+
153
+ ### `envx decrypt`
154
+ Decrypt environment files.
155
+
156
+ ```bash
157
+ # Decrypt specific environment
158
+ envx decrypt -e production
159
+
160
+ # Overwrite existing files without confirmation
161
+ envx decrypt -e development --overwrite
162
+
163
+ # Interactive file selection
164
+ envx decrypt -e staging -i
165
+ ```
166
+
167
+ **Options:**
168
+ - `-e, --environment <env>` - Environment name (required)
169
+ - `-p, --passphrase <pass>` - Decryption passphrase
170
+ - `-s, --secret <secret>` - Secret variable name from .envrc
171
+ - `-i, --interactive` - Interactive file selection
172
+ - `--overwrite` - Overwrite existing files without confirmation
173
+ - `-c, --cwd <path>` - Working directory
174
+
175
+ ### `envx interactive`
176
+ Interactive setup for `.envrc` file with secrets.
177
+
178
+ ```bash
179
+ # Start interactive setup
180
+ envx interactive
181
+
182
+ # Overwrite existing .envrc
183
+ envx interactive --overwrite
184
+
185
+ # Generate random secrets for all environments
186
+ envx interactive --generate
187
+ ```
188
+
189
+ **Options:**
190
+ - `--overwrite` - Overwrite existing .envrc file
191
+ - `--generate` - Generate random secrets
192
+ - `-c, --cwd <path>` - Working directory
193
+
194
+ ### `envx list`
195
+ List all environment files and their status.
196
+
197
+ ```bash
198
+ # List all environment files
199
+ envx list
200
+
201
+ # Short alias
202
+ envx ls
203
+ ```
204
+
205
+ **Options:**
206
+ - `-c, --cwd <path>` - Working directory
207
+
208
+ ### `envx status`
209
+ Show project encryption status and recommendations.
210
+
211
+ ```bash
212
+ envx status
213
+ ```
214
+
215
+ **Options:**
216
+ - `-c, --cwd <path>` - Working directory
217
+
218
+ ## Workflow Examples
219
+
220
+ ### Basic Workflow
221
+
222
+ 1. **Create environment files:**
223
+ ```bash
224
+ envx create -e development
225
+ envx create -e production
226
+ ```
227
+
228
+ 2. **Edit your environment files:**
229
+ ```bash
230
+ # Edit .env.development
231
+ echo "DATABASE_URL=postgresql://localhost:5432/myapp_dev" >> .env.development
232
+ echo "API_KEY=dev-api-key" >> .env.development
233
+
234
+ # Edit .env.production
235
+ echo "DATABASE_URL=postgresql://prod-server:5432/myapp" >> .env.production
236
+ echo "API_KEY=prod-api-key-secret" >> .env.production
237
+ ```
238
+
239
+ 3. **Set up encryption secrets:**
240
+ ```bash
241
+ envx interactive
242
+ ```
243
+
244
+ 4. **Encrypt production secrets:**
245
+ ```bash
246
+ envx encrypt -e production
247
+ ```
248
+
249
+ 5. **Add to version control:**
250
+ ```bash
251
+ echo ".env.*" >> .gitignore
252
+ echo "!*.gpg" >> .gitignore
253
+ git add .env.production.gpg .envrc
254
+ git commit -m "Add encrypted production environment"
255
+ ```
256
+
257
+ ### Team Workflow
258
+
259
+ 1. **Clone repository and decrypt:**
260
+ ```bash
261
+ git clone <your-repo>
262
+ cd <your-repo>
263
+ envx decrypt -e production
264
+ ```
265
+
266
+ 2. **Make changes and re-encrypt:**
267
+ ```bash
268
+ # Edit .env.production
269
+ envx encrypt -e production
270
+ git add .env.production.gpg
271
+ git commit -m "Update production configuration"
272
+ ```
273
+
274
+ ## Configuration
275
+
276
+ ### `.envrc` File
277
+
278
+ EnvX uses `.envrc` files to store encryption secrets. The format follows the direnv convention:
279
+
280
+ ```bash
281
+ # Environment secrets generated by envx
282
+ export DEVELOPMENT_SECRET="your-development-secret"
283
+ export STAGING_SECRET="your-staging-secret"
284
+ export PRODUCTION_SECRET="your-production-secret"
285
+ ```
286
+
287
+ ### Secret Variable Naming
288
+
289
+ EnvX follows the convention: `<STAGE>_SECRET`
290
+
291
+ Examples:
292
+ - `DEVELOPMENT_SECRET`
293
+ - `STAGING_SECRET`
294
+ - `PRODUCTION_SECRET`
295
+ - `LOCAL_SECRET`
296
+
297
+ ### File Structure
298
+
299
+ ```
300
+ your-project/
301
+ ├── .env.development # Unencrypted (local only)
302
+ ├── .env.staging.gpg # Encrypted (committed)
303
+ ├── .env.production.gpg # Encrypted (committed)
304
+ ├── .envrc # Secrets (local only)
305
+ └── .gitignore # Excludes .env.* but allows *.gpg
306
+ ```
307
+
308
+ ## Security Best Practices
309
+
310
+ ### ✅ Do's
311
+
312
+ - ✅ Always encrypt production and staging environment files
313
+ - ✅ Commit encrypted `.gpg` files to version control
314
+ - ✅ Add `.envrc` to your `.gitignore`
315
+ - ✅ Use strong, unique secrets for each environment
316
+ - ✅ Regularly rotate encryption secrets
317
+ - ✅ Use `envx status` to check your security posture
318
+
319
+ ### ❌ Don'ts
320
+
321
+ - ❌ Never commit unencrypted `.env.*` files (except templates)
322
+ - ❌ Don't commit `.envrc` files to version control
323
+ - ❌ Don't use weak or predictable passphrases
324
+ - ❌ Don't share secrets through insecure channels
325
+ - ❌ Don't leave decrypted files in production environments
326
+
327
+ ### Recommended `.gitignore`
328
+
329
+ ```gitignore
330
+ # Environment files
331
+ .env.*
332
+ !.env.example
333
+ !.env.template
334
+ !*.gpg
335
+
336
+ # EnvX secrets
337
+ .envrc
338
+ ```
339
+
340
+ ## Integration with Direnv
341
+
342
+ EnvX works great with [direnv](https://direnv.net/) for automatic environment loading:
343
+
344
+ 1. **Install direnv:**
345
+ ```bash
346
+ # macOS
347
+ brew install direnv
348
+
349
+ # Ubuntu/Debian
350
+ sudo apt install direnv
351
+ ```
352
+
353
+ 2. **Add to your shell profile:**
354
+ ```bash
355
+ # For bash
356
+ echo 'eval "$(direnv hook bash)"' >> ~/.bashrc
357
+
358
+ # For zsh
359
+ echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc
360
+ ```
361
+
362
+ 3. **Allow direnv in your project:**
363
+ ```bash
364
+ direnv allow
365
+ ```
366
+
367
+ Now your secrets will be automatically loaded when you enter the project directory!
368
+
369
+ ## Troubleshooting
370
+
371
+ ### GPG Issues
372
+
373
+ **Problem:** `gpg: command not found`
374
+ ```bash
375
+ # Install GPG (see Prerequisites section)
376
+ ```
377
+
378
+ **Problem:** `gpg: decryption failed: Bad session key`
379
+ ```bash
380
+ # Wrong passphrase - try again or check your .envrc file
381
+ envx decrypt -e production
382
+ ```
383
+
384
+ **Problem:** `gpg: can't connect to the agent`
385
+ ```bash
386
+ # Restart GPG agent
387
+ gpgconf --kill gpg-agent
388
+ gpgconf --launch gpg-agent
389
+ ```
390
+
391
+ ### Permission Issues
392
+
393
+ **Problem:** `EACCES: permission denied`
394
+ ```bash
395
+ # Check file permissions
396
+ ls -la .env.*
397
+ chmod 644 .env.*
398
+ ```
399
+
400
+ ### File Not Found
401
+
402
+ **Problem:** `Template file not found`
403
+ ```bash
404
+ # Check if template exists
405
+ ls -la .env.example
406
+ # Or create without template
407
+ envx create -e development
408
+ ```
409
+
410
+ ## API Reference
411
+
412
+ ### Environment Variables
413
+
414
+ EnvX respects the following environment variables:
415
+
416
+ - `ENVX_DEFAULT_CWD` - Default working directory
417
+ - `ENVX_GPG_BINARY` - Custom GPG binary path
418
+ - `NODE_ENV` - Affects error reporting verbosity
419
+
420
+ ### Exit Codes
421
+
422
+ - `0` - Success
423
+ - `1` - General error
424
+ - `2` - Invalid arguments
425
+ - `3` - File operation failed
426
+ - `4` - GPG operation failed
427
+
428
+ ## Testing
429
+
430
+ EnvX includes a streamlined test suite focused on essential functionality and real-world CLI usage scenarios.
431
+
432
+ ### Running Tests
433
+
434
+ ```bash
435
+ # Run all tests
436
+ npm test
437
+
438
+ # Run core functionality tests
439
+ npm run test:core
440
+
441
+ # Run integration tests
442
+ npm run test:integration
443
+
444
+ # Run tests with coverage
445
+ npm run test:coverage
446
+
447
+ # Run tests in watch mode (for development)
448
+ npm run test:watch
449
+ ```
450
+
451
+ ### Testing Philosophy
452
+
453
+ The test suite prioritizes **essential functionality** over comprehensive coverage:
454
+
455
+ - ✅ **Core business logic** - Command validation, file utilities, path manipulation
456
+ - ✅ **Real CLI scenarios** - Actual command execution in various environments
457
+ - ✅ **Critical workflows** - User-facing functionality that must work reliably
458
+ - ❌ **UI/cosmetic features** - Colors, formatting, and visual elements
459
+ - ❌ **Complex mocking** - Simplified approach focusing on actual behavior
460
+
461
+ ### Test Coverage
462
+
463
+ **Current Status**: ✅ 95 tests passing, ~7s execution time
464
+
465
+ - **Core Tests**: 82 tests covering essential functionality
466
+ - Schema validation: 25 tests (command input validation)
467
+ - File utilities: 39 tests (path manipulation, secret generation)
468
+ - Command logic: 18 tests (workflow patterns and decision logic)
469
+
470
+ - **Integration Tests**: 13 tests covering real CLI usage
471
+ - Help/version commands
472
+ - Create command functionality
473
+ - Error handling scenarios
474
+ - Environment validation
475
+
476
+ ### Test Structure
477
+
478
+ ```
479
+ __tests__/
480
+ ├── core/ # Essential functionality tests
481
+ │ ├── schemas.test.ts # Input validation for all commands
482
+ │ ├── file.test.ts # File utilities and path manipulation
483
+ │ └── commands.test.ts # Command workflow logic patterns
484
+ └── integration/ # End-to-end CLI tests
485
+ └── cli.test.ts # Real CLI execution scenarios
486
+ ```
487
+
488
+ For detailed testing information, see [TESTING.md](TESTING.md).
489
+
490
+ ## Development
491
+
492
+ ### Building from Source
493
+
494
+ ```bash
495
+ git clone https://github.com/rahulretnan/envx-cli
496
+ cd envx-cli
497
+ npm install
498
+ npm run build
499
+ npm link
500
+ ```
501
+
502
+ ### Development Workflow
503
+
504
+ ```bash
505
+ # Start development mode
506
+ npm run dev
507
+
508
+ # Run tests in watch mode
509
+ npm run test:watch
510
+
511
+ # Build and test
512
+ npm run build && npm test
513
+ ```
514
+
515
+ ### Contributing
516
+
517
+ 1. Fork the repository
518
+ 2. Create a feature branch: `git checkout -b feature-name`
519
+ 3. Make your changes and add tests
520
+ 4. Run tests: `npm test`
521
+ 5. Ensure test coverage remains high: `npm run test:coverage`
522
+ 6. Submit a pull request
523
+
524
+ #### Test Requirements
525
+
526
+ - New CLI commands must include integration tests
527
+ - Core utility functions must include unit tests
528
+ - Focus on user-facing functionality over implementation details
529
+ - Keep tests simple and maintainable
530
+ - Ensure tests verify real CLI behavior
531
+
532
+ ## Changelog
533
+
534
+ See [CHANGELOG.md](CHANGELOG.md) for detailed release notes.
535
+
536
+ ## License
537
+
538
+ MIT © [rahulretnan](https://github.com/rahulretnan)
539
+
540
+ ## Support
541
+
542
+ - 📝 [Issues](https://github.com/rahulretnan/envx-cli/issues)
543
+ - 💬 [Discussions](https://github.com/rahulretnan/envx-cli/discussions)
544
+ - 📧 Email: hi@rahulretnan.me
545
+
546
+ ---
547
+
548
+ **Made with ❤️ by developers, for developers.**
549
+
550
+ *Remember: Security is not a feature, it's a requirement. EnvX helps you maintain security without sacrificing developer experience.*
@@ -0,0 +1,3 @@
1
+ import { Command } from "commander";
2
+ export declare const createCreateCommand: () => Command;
3
+ //# sourceMappingURL=create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/commands/create.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,eAAO,MAAM,mBAAmB,QAAO,OA4BtC,CAAC"}