env-checklist 1.2.0 โ†’ 1.2.9

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 (2) hide show
  1. package/README.md +178 -2
  2. package/package.json +6 -2
package/README.md CHANGED
@@ -3,14 +3,17 @@
3
3
  A lightweight, color-coded CLI tool to ensure your local environment variables match your `.env.example` before you launch your app.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/env-checklist.svg)](https://www.npmjs.com/package/env-checklist)
6
- [![license](https://img.shields.io/npm/l/env-checklist.svg)](https://github.com/YOUR_GITHUB_USERNAME/env-checklist)
6
+ [![license](https://img.shields.io/npm/l/env-checklist.svg)](https://github.com/tangorishi/env-checklist)
7
7
 
8
8
  ## ๐Ÿš€ Why use this?
9
+
9
10
  How many times has your app crashed because you forgot to add a new API key to your `.env` file? `env-checklist` prevents that by comparing your active `.env` against your template.
10
11
 
11
12
  - **๐ŸŽจ Beautiful Terminal Output**: Uses Chalk for high-contrast success/error messages.
12
13
  - **๐Ÿ›ก๏ธ Robust Parsing**: Automatically ignores comments and empty lines.
13
14
  - **๐Ÿ“ฆ Zero Config**: Works out of the box with any Node.js project.
15
+ - **๐Ÿ”‘ Optional Keys**: Mark variables as optional directly in your `.env.example`.
16
+ - **๐Ÿ›  Programmatic API**: Use `preflight()` or `preflightSafe()` directly in your code.
14
17
 
15
18
  ---
16
19
 
@@ -18,5 +21,178 @@ How many times has your app crashed because you forgot to add a new API key to y
18
21
 
19
22
  ### Run once (Recommended)
20
23
  You don't even need to install it. Just run this in your project root:
24
+
25
+ ```bash
26
+ npx env-checklist@latest
27
+ ```
28
+
29
+ ### Install globally
30
+ ```bash
31
+ npm install -g env-checklist
32
+ env-checklist
33
+ ```
34
+
35
+ ### Install as a dev dependency
36
+ ```bash
37
+ npm install --save-dev env-checklist
38
+ ```
39
+
40
+ Add it to your `package.json` scripts to run before starting your app:
41
+
42
+ ```json
43
+ "scripts": {
44
+ "prestart": "env-checklist",
45
+ "start": "node dist/index.js"
46
+ }
47
+ ```
48
+
49
+ ---
50
+
51
+ ## ๐Ÿšฉ CLI Flags
52
+
53
+ | Flag | Alias | Description |
54
+ |------|-------|-------------|
55
+ | `--verbose` | | Show a status line for every key checked |
56
+ | `--fix` | | Auto-generate a `.env` file from `.env.example` with empty placeholders |
57
+ | `--path <file>` | | Use a custom `.env.example` path (useful in monorepos) |
58
+ | `--version` | `-v` | Show the current version |
59
+ | `--help` | `-h` | Show the help message |
60
+
61
+ ### Examples
62
+
21
63
  ```bash
22
- npx env-checklist@latest
64
+ # Basic check
65
+ npx env-checklist
66
+
67
+ # See every key's status
68
+ npx env-checklist --verbose
69
+
70
+ # Auto-generate a .env scaffold
71
+ npx env-checklist --fix
72
+
73
+ # Use a custom .env.example path (monorepos)
74
+ npx env-checklist --path apps/api/.env.example
75
+
76
+ # Check version
77
+ npx env-checklist --version
78
+ ```
79
+
80
+ ### `--verbose` output example
81
+
82
+ ```
83
+ โœˆ๏ธ Checking environment variables...
84
+
85
+ KEY TYPE STATUS
86
+ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
87
+ PORT required โœ… present
88
+ API_KEY required โœ… present
89
+ DATABASE_URL required โŒ missing
90
+ SENTRY_DSN optional โž– not set
91
+
92
+ โŒ Preflight Failed!
93
+
94
+ Missing required variables:
95
+ โœ– DATABASE_URL
96
+
97
+ 2 passed ยท 1 failed ยท 4 total
98
+ ```
99
+
100
+ ### `--fix` output example
101
+
102
+ ```bash
103
+ npx env-checklist --fix
104
+ # โœ… .env file created from .env.example.
105
+ # 3 variable(s) scaffolded. Fill in the values before launching.
106
+ ```
107
+
108
+ ---
109
+
110
+ ## ๐Ÿ”‘ Optional Keys
111
+
112
+ Mark any variable as optional in your `.env.example` by adding `# optional` to the end of the line. Optional keys are loaded into the config if present but never cause a failure.
113
+
114
+ ```bash
115
+ # .env.example
116
+ PORT=
117
+ API_KEY=
118
+ DATABASE_URL=
119
+ SENTRY_DSN= # optional
120
+ LOG_LEVEL= # optional
121
+ ```
122
+
123
+ ---
124
+
125
+ ## ๐Ÿ“ฆ Programmatic API
126
+
127
+ ### `preflight(keys)` โ€” strict mode
128
+
129
+ Throws a `PreflightError` if any required key is missing. Accepts a plain array or an options object.
130
+
131
+ ```ts
132
+ import { preflight } from 'env-checklist';
133
+
134
+ // Simple โ€” required keys only
135
+ const config = preflight(['PORT', 'API_KEY', 'DATABASE_URL']);
136
+
137
+ // With optional keys
138
+ const config = preflight({
139
+ required: ['PORT', 'API_KEY'],
140
+ optional: ['SENTRY_DSN', 'LOG_LEVEL'],
141
+ });
142
+
143
+ console.log(config.PORT); // '3000'
144
+ ```
145
+
146
+ ### `preflightSafe(keys)` โ€” safe mode
147
+
148
+ Never throws. Returns a result object โ€” ideal when you want to handle errors yourself.
149
+
150
+ ```ts
151
+ import { preflightSafe } from 'env-checklist';
152
+
153
+ const result = preflightSafe({
154
+ required: ['PORT', 'API_KEY'],
155
+ optional: ['SENTRY_DSN'],
156
+ });
157
+
158
+ if (!result.ok) {
159
+ console.error('Missing:', result.missing);
160
+ process.exit(1);
161
+ }
162
+
163
+ console.log(result.config); // { PORT: '3000', API_KEY: '...' }
164
+ console.log(result.present); // ['PORT', 'API_KEY']
165
+ console.log(result.optionalMissing); // ['SENTRY_DSN']
166
+ ```
167
+
168
+ ### `PreflightError`
169
+
170
+ ```ts
171
+ import { preflight, PreflightError } from 'env-checklist';
172
+
173
+ try {
174
+ preflight(['PORT', 'API_KEY']);
175
+ } catch (e) {
176
+ if (e instanceof PreflightError) {
177
+ console.error('Missing keys:', e.missing); // ['API_KEY']
178
+ }
179
+ }
180
+ ```
181
+
182
+ ---
183
+
184
+ ## ๐Ÿค Contributing
185
+
186
+ Contributions are welcome! Please open an issue or submit a pull request on [GitHub](https://github.com/tangorishi/env-checklist).
187
+
188
+ 1. Fork the repo
189
+ 2. Create your branch: `git checkout -b usr/your-name`
190
+ 3. Make your changes and add tests
191
+ 4. Run `npm test` to verify
192
+ 5. Open a PR against `main`
193
+
194
+ ---
195
+
196
+ ## ๐Ÿ“„ License
197
+
198
+ MIT ยฉ [Rishi Joshi](https://github.com/tangorishi)
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "env-checklist",
3
- "version": "1.2.0",
3
+ "version": "1.2.9",
4
4
  "description": "Ensure your environment variables are flight-ready before takeoff.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
9
9
  "bin": {
10
- "env-checklist": "./dist/cli.js"
10
+ "env-checklist": "dist/cli.js"
11
11
  },
12
12
  "files": [
13
13
  "dist"
@@ -30,6 +30,10 @@
30
30
  ],
31
31
  "author": "Rishi Joshi",
32
32
  "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/tangorishi/env-checklist.git"
36
+ },
33
37
  "devDependencies": {
34
38
  "@types/node": "^20.11.0",
35
39
  "tsup": "^8.5.1",