env-drift-check 0.1.0 → 0.1.2

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 CHANGED
@@ -1,46 +1,52 @@
1
- # env-drift-check
1
+ # env-drift-check: Automatic .env Sync & Validation
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/env-drift-check.svg)](https://www.npmjs.com/package/env-drift-check)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
5
 
6
- > **Stop copy-pasting `.env` files.** Onboard developers in seconds with interactive prompts and smart validation.
6
+ > **Stop copy-pasting `.env` files.** Onboard developers in seconds with interactive prompts, smart schema validation, and drift detection.
7
7
 
8
- **env-drift-check** is a powerful CLI tool that ensures your environment variables are always in sync with your code. Unlike other tools that just fail when keys are missing, we help you **fix them interactively**.
8
+ **env-drift-check** is the ultimate CLI tool for managing environment variables in Node.js projects. It ensures your local `.env` file is always in sync with `.env.example`, preventing runtime errors caused by missing keys. Perfect for teams and CI/CD pipelines.
9
+
10
+ ![env-drift-check demo](./public/env-drift-check.png)
9
11
 
10
12
  ## Why use this?
11
13
 
12
- | Feature | Other Tools | **env-drift-check** |
14
+ | Feature | Other Tools (dotenv-safe, etc.) | **env-drift-check** |
13
15
  | :--- | :--- | :--- |
14
- | **Missing Keys** | Crash & Exit | 🛠 **Interactive Setup Wizard** |
15
- | **Validation** | Basic Existence Check | **Rich Types** (Email, URL, Regex) |
16
- | **Onboarding** | Manual (Read docs → Copy → Paste) | **Automated** (Run command → Fill prompts) |
16
+ | **Missing Keys** | Crash & Exit | **Interactive Setup Wizard** |
17
+ | **Validation** | Basic Existence Check | **Rich Types** (Email, URL, Regex, Number) |
18
+ | **Onboarding** | Manual (Read docs → Copy → Paste) | **Automated** (Run command → Fill prompts) |
19
+ | **Drift Detection** | Static | **Real-time** comparison with `.env.example` |
17
20
 
18
21
  ## Features
19
22
 
20
- - **Interactive Mode**: Automatically prompts users to fill in missing variables.
21
- - **Smart Validation**: enforce types like `email`, `url`, `number`, `boolean`, and `regex`.
22
- - **Drift Detection**: Compares your `.env` against `.env.example`.
23
- - **Zero Config**: Works out of the box, or add `envwise.config.json` for superpowers.
23
+ - **Interactive Mode**: Automatically detects missing keys and prompts you to fill them in via CLI.
24
+ - **Smart Schema Validation**: Enforce types like `email`, `url`, `number`, `boolean`, `enum`, and custom `regex`.
25
+ - **Drift Detection**: Instantly compare your local environment against the team's `.env.example`.
26
+ - **CI/CD Ready**: Use strict mode to fail builds if environment variables are missing or invalid.
27
+ - **Zero Config**: Works out of the box, or add `envwise.config.json` for advanced validation rules.
24
28
 
25
29
  ## Installation
26
30
 
31
+ Install globally or as a dev dependency:
32
+
27
33
  ```bash
28
34
  npm install -g env-drift-check
29
35
  # OR
30
- npx env-drift-check
36
+ npm install --save-dev env-drift-check
31
37
  ```
32
38
 
33
39
  ## 🛠 Usage
34
40
 
35
41
  ### 1. Basic Check
36
- Check if your `.env` is missing any keys defined in `.env.example`:
42
+ Check if your `.env` is missing any keys defined in `.env.example`. This is great for a quick status check.
37
43
 
38
44
  ```bash
39
45
  npx env-drift-check
40
46
  ```
41
47
 
42
48
  ### 2. Interactive Setup (Recommended)
43
- Automatically prompt the user to fill in missing keys:
49
+ The **interactive mode** is the star feature. If missing keys are found, it launches a wizard to help you fill them in without leaving your terminal.
44
50
 
45
51
  ```bash
46
52
  npx env-drift-check --interactive
@@ -48,8 +54,14 @@ npx env-drift-check --interactive
48
54
  npx env-drift-check -i
49
55
  ```
50
56
 
57
+ ![Interactive update](./public/env-drift-check-i-update.png)
58
+
59
+ Once completed, your `.env` file is automatically updated!
60
+
61
+ ![Interactive success](./public/env-drift-check-i-final.png)
62
+
51
63
  ### 3. CI/CD Mode (Strict)
52
- Fail the build if drift is detected (great for pipelines):
64
+ Ensure no broken code hits production. Use strict mode in your build pipeline to fail if environment variables are missing.
53
65
 
54
66
  ```bash
55
67
  npx env-drift-check --strict
@@ -57,7 +69,7 @@ npx env-drift-check --strict
57
69
 
58
70
  ## Configuration
59
71
 
60
- Create a `envwise.config.json` to define validation rules.
72
+ Create a `envwise.config.json` file in your root directory to define validation rules and defaults. This acts as a schema for your environment variables.
61
73
 
62
74
  ```json
63
75
  {
@@ -66,24 +78,25 @@ Create a `envwise.config.json` to define validation rules.
66
78
  "PORT": {
67
79
  "type": "number",
68
80
  "min": 3000,
69
- "max": 9000
81
+ "max": 9000,
82
+ "description": "Port the server should listen on"
70
83
  },
71
84
  "DATABASE_URL": {
72
85
  "type": "url",
73
- "description": "Connection string for MongoDB"
86
+ "description": "Connection string for MongoDB/PostgreSQL"
74
87
  },
75
88
  "ADMIN_EMAIL": {
76
89
  "type": "email",
77
90
  "required": true
78
91
  },
79
- "FEATURE_FLAG": {
80
- "type": "boolean",
81
- "mustBeFalseIn": "production"
92
+ "ENVIRONMENT": {
93
+ "type": "enum",
94
+ "values": ["development", "production", "test"]
82
95
  },
83
96
  "API_KEY": {
84
97
  "type": "regex",
85
98
  "regex": "^[A-Z0-9]{32}$",
86
- "description": "32-character alphanumeric key"
99
+ "description": "32-character alphanumeric API key"
87
100
  }
88
101
  }
89
102
  }
@@ -93,21 +106,23 @@ Create a `envwise.config.json` to define validation rules.
93
106
 
94
107
  | Type | Options | Description |
95
108
  | :--- | :--- | :--- |
96
- | `string` | `min`, `max` | String length validation |
97
- | `number` | `min`, `max` | Numeric range validation |
98
- | `boolean` | `mustBeFalseIn` | True/False check |
99
- | `enum` | `values` (array) | Must be one of the allowlist |
100
- | `email` | - | Valid email format |
101
- | `url` | - | Valid URL format |
102
- | `regex` | `regex` (string) | Custom pattern matching |
109
+ | `string` | `min`, `max` | Validate string length. |
110
+ | `number` | `min`, `max` | Validate numeric ranges. |
111
+ | `boolean` | `mustBeFalseIn` | Ensure flags (like debug mode) are off in prod. |
112
+ | `enum` | `values` (array) | Restrict to a set of allowed values. |
113
+ | `email` | - | Validate standard email formats. |
114
+ | `url` | - | Validate URL structure. |
115
+ | `regex` | `regex` (string) | Custom pattern matching for keys, secrets, etc. |
103
116
 
104
117
  ## Contributing
105
118
 
106
- 1. Fork the repository
107
- 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
108
- 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
109
- 4. Push to the branch (`git push origin feature/amazing-feature`)
110
- 5. Open a Pull Request
119
+ We welcome contributions! Please follow these steps:
120
+
121
+ 1. Fork the repository.
122
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`).
123
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`).
124
+ 4. Push to the branch (`git push origin feature/amazing-feature`).
125
+ 5. Open a Pull Request.
111
126
 
112
127
  ## License
113
128
 
@@ -5,11 +5,46 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.parseEnv = parseEnv;
7
7
  const fs_1 = __importDefault(require("fs"));
8
- const dotenv_1 = __importDefault(require("dotenv"));
9
8
  function parseEnv(path) {
10
9
  if (!fs_1.default.existsSync(path)) {
11
10
  throw new Error(`Env file not found: ${path}`);
12
11
  }
13
- const content = fs_1.default.readFileSync(path);
14
- return dotenv_1.default.parse(content);
12
+ const content = fs_1.default.readFileSync(path, 'utf8');
13
+ const result = {};
14
+ // Split into lines and process each
15
+ const lines = content.split(/\r?\n/);
16
+ for (const line of lines) {
17
+ const trimmed = line.trim();
18
+ // Skip empty lines and comments
19
+ if (!trimmed || trimmed.startsWith('#'))
20
+ continue;
21
+ // Match KEY=VALUE (taking the first '=' as the separator)
22
+ const firstEqual = trimmed.indexOf('=');
23
+ if (firstEqual === -1)
24
+ continue;
25
+ const key = trimmed.slice(0, firstEqual).trim();
26
+ const rawValue = trimmed.slice(firstEqual + 1).trim();
27
+ let value = "";
28
+ if (rawValue.startsWith('"') || rawValue.startsWith("'")) {
29
+ const quote = rawValue[0];
30
+ const closingQuoteIndex = rawValue.indexOf(quote, 1);
31
+ if (closingQuoteIndex !== -1) {
32
+ value = rawValue.slice(1, closingQuoteIndex);
33
+ }
34
+ else {
35
+ value = rawValue.slice(1); // Unclosed quote
36
+ }
37
+ }
38
+ else {
39
+ const hashIndex = rawValue.indexOf('#');
40
+ if (hashIndex !== -1) {
41
+ value = rawValue.slice(0, hashIndex).trim();
42
+ }
43
+ else {
44
+ value = rawValue;
45
+ }
46
+ }
47
+ result[key] = value;
48
+ }
49
+ return result;
15
50
  }
@@ -17,8 +17,7 @@ function report(result) {
17
17
  if (result.mismatches.length) {
18
18
  console.log("\n Value Mismatches:");
19
19
  result.mismatches.forEach(m => {
20
- console.log(` - ${m.key}: expected="${m.expected}" actual="${m.actual}"`);
21
- console.log(` -Run --fix to sync ${m.key}`);
20
+ console.log(` - ${m.key.padEnd(15)} Expected: ${m.expected.padEnd(12)} Actual: ${m.actual}`);
22
21
  });
23
22
  }
24
23
  if (!result.missing.length &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "env-drift-check",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Interactive environment variable checker and setup wizard. Sync .env files with validation (Email, URL, Regex) and prompts.",
5
5
  "keywords": [
6
6
  "env",
@@ -42,7 +42,6 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "commander": "^11.0.0",
45
- "dotenv": "^16.4.0",
46
45
  "prompts": "^2.4.2"
47
46
  },
48
47
  "devDependencies": {