env-drift-check 0.1.4 ā 0.1.6
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 +56 -52
- package/dist/cli.js +85 -46
- package/dist/config/loadConfig.d.ts +6 -0
- package/dist/config/loadConfig.js +6 -0
- package/dist/engine/driftChecker.d.ts +9 -0
- package/dist/engine/driftChecker.js +9 -0
- package/dist/engine/envParser.d.ts +8 -0
- package/dist/engine/envParser.js +8 -0
- package/dist/engine/interactive.d.ts +9 -0
- package/dist/engine/interactive.js +9 -0
- package/dist/engine/validator.d.ts +10 -0
- package/dist/engine/validator.js +10 -0
- package/dist/types.d.ts +27 -0
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -1,75 +1,84 @@
|
|
|
1
|
-
# env-drift-check:
|
|
1
|
+
# env-drift-check: Interactive .env Sync & Validation for Teams
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/env-drift-check)
|
|
4
|
+
[](https://www.npmjs.com/package/env-drift-check)
|
|
4
5
|
[](https://opensource.org/licenses/MIT)
|
|
5
6
|
|
|
6
|
-
> **
|
|
7
|
+
> **Eliminate "It works on my machine" issues.** Synchronize `.env` files across your team with interactive prompts, smart schema validation, and real-time drift detection.
|
|
7
8
|
|
|
8
|
-
**env-drift-check** is
|
|
9
|
+
**env-drift-check** is a powerful CLI utility designed to manage environment variables in Node.js applications. It ensures your local `.env` remains in perfect sync with `.env.example`, preventing runtime crashes and streamlining developer onboarding.
|
|
9
10
|
|
|
10
11
|

|
|
11
12
|
|
|
12
|
-
##
|
|
13
|
+
## š Why Use env-drift-check?
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
Manually managing environment variables is error-prone. **env-drift-check** automates the process:
|
|
16
|
+
|
|
17
|
+
| Pain Point | Standard Approach | **env-drift-check** |
|
|
15
18
|
| :--- | :--- | :--- |
|
|
16
|
-
| **Missing Keys** |
|
|
17
|
-
| **
|
|
18
|
-
| **Onboarding** |
|
|
19
|
-
| **Drift
|
|
19
|
+
| **Missing Keys** | Application crashes at runtime | **Interactive Setup Wizard** fills them |
|
|
20
|
+
| **Type Safety** | String-only values, no validation | **Rich Validation** (Email, URL, Regex) |
|
|
21
|
+
| **Team Onboarding** | "Copy this file from Slack/Docs" | `npx env-drift-check init` & sync |
|
|
22
|
+
| **Configuration Drift** | Desync between dev/stage/prod | **Real-time Detection** against template |
|
|
20
23
|
|
|
21
|
-
|
|
24
|
+
### Key Features
|
|
22
25
|
|
|
23
|
-
- **Interactive Mode**: Automatically detects missing keys and prompts you to fill them in via CLI.
|
|
24
|
-
- **Smart Schema Validation**: Enforce types
|
|
25
|
-
- **
|
|
26
|
-
- **CI/CD Ready**: Use strict mode
|
|
27
|
-
- **Zero Config**: Works out of the box, or add `envwise.config.json` for advanced validation rules.
|
|
26
|
+
- **Interactive Mode**: Automatically detects missing keys and prompts you to fill them in directly via the CLI.
|
|
27
|
+
- **Smart Schema Validation**: Enforce strict types including `email`, `url`, `number`, `boolean`, `enum`, and custom `regex`.
|
|
28
|
+
- **Zero Config Setup**: Works out of the box. Add an optional `envwise.config.json` for advanced rules.
|
|
29
|
+
- **CI/CD Ready**: Use `--strict` mode in your build pipeline to prevent deployments with missing variables.
|
|
28
30
|
|
|
29
|
-
##
|
|
31
|
+
## š Documentation
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
- [CLI Usage](./docs/CLI-Usage.md) - Detailed flags and command examples.
|
|
34
|
+
- [Configuration](./docs/Configuration.md) - Advanced types and `envwise.config.json` schema.
|
|
35
|
+
- [Programmatic API](./docs/API-Reference.md) - Integrating the validation engine into your code.
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
32
38
|
|
|
33
39
|
```bash
|
|
34
|
-
|
|
35
|
-
# OR
|
|
40
|
+
# Install as a dev dependency (Recommended)
|
|
36
41
|
npm install --save-dev env-drift-check
|
|
42
|
+
|
|
43
|
+
# OR install globally
|
|
44
|
+
npm install -g env-drift-check
|
|
37
45
|
```
|
|
38
46
|
|
|
39
47
|
## Usage
|
|
40
48
|
|
|
41
|
-
### 1.
|
|
42
|
-
|
|
49
|
+
### 1. Initialize (New Setup)
|
|
50
|
+
Bootstrap your project by creating a configuration and an example environment file.
|
|
51
|
+
```bash
|
|
52
|
+
npx env-drift-check init
|
|
53
|
+
```
|
|
43
54
|
|
|
55
|
+
### 2. Basic Check
|
|
56
|
+
Compare your `.env` against the reference (default: `.env.example`).
|
|
44
57
|
```bash
|
|
45
58
|
npx env-drift-check
|
|
59
|
+
# Specify a custom reference file
|
|
60
|
+
npx env-drift-check --base .env.production
|
|
46
61
|
```
|
|
47
62
|
|
|
48
|
-
###
|
|
49
|
-
|
|
50
|
-
|
|
63
|
+
### 3. Interactive Sync (The "Magic" Feature)
|
|
64
|
+
If missing variables are found, launch the interactive wizard to fill them in without leaving your IDE.
|
|
51
65
|
```bash
|
|
52
66
|
npx env-drift-check --interactive
|
|
53
67
|
# OR
|
|
54
68
|
npx env-drift-check -i
|
|
55
69
|
```
|
|
56
70
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
Once completed, your `.env` file is automatically updated!
|
|
60
|
-
|
|
61
|
-

|
|
62
|
-
|
|
63
|
-
### 3. CI/CD Mode (Strict)
|
|
64
|
-
Ensure no broken code hits production. Use strict mode in your build pipeline to fail if environment variables are missing.
|
|
65
|
-
|
|
71
|
+
### 4. CI/CD & Strict Mode
|
|
72
|
+
Fail your build or test suite if environment variables are out of sync.
|
|
66
73
|
```bash
|
|
67
74
|
npx env-drift-check --strict
|
|
68
75
|
```
|
|
69
76
|
|
|
70
|
-
|
|
77
|
+
---
|
|
71
78
|
|
|
72
|
-
|
|
79
|
+
## š Advanced Configuration
|
|
80
|
+
|
|
81
|
+
Define validation rules in `envwise.config.json` to ensure data integrity across environments.
|
|
73
82
|
|
|
74
83
|
```json
|
|
75
84
|
{
|
|
@@ -92,31 +101,26 @@ Create a `envwise.config.json` file in your root directory to define validation
|
|
|
92
101
|
"ENVIRONMENT": {
|
|
93
102
|
"type": "enum",
|
|
94
103
|
"values": ["development", "production", "test"]
|
|
95
|
-
},
|
|
96
|
-
"API_KEY": {
|
|
97
|
-
"type": "regex",
|
|
98
|
-
"regex": "^[A-Z0-9]{32}$",
|
|
99
|
-
"description": "32-character alphanumeric API key"
|
|
100
104
|
}
|
|
101
105
|
}
|
|
102
106
|
}
|
|
103
107
|
```
|
|
104
108
|
|
|
105
|
-
### Validation Types
|
|
109
|
+
### Supported Validation Types
|
|
106
110
|
|
|
107
|
-
| Type |
|
|
111
|
+
| Type | Description | Example Rule |
|
|
108
112
|
| :--- | :--- | :--- |
|
|
109
|
-
| `string` | `min
|
|
110
|
-
| `number` | `min
|
|
111
|
-
| `boolean` |
|
|
112
|
-
| `enum` |
|
|
113
|
-
| `email` |
|
|
114
|
-
| `url` |
|
|
115
|
-
| `regex` |
|
|
113
|
+
| `string` | Length validation | `{ "min": 5, "max": 20 }` |
|
|
114
|
+
| `number` | Range validation | `{ "min": 1, "max": 100 }` |
|
|
115
|
+
| `boolean` | Flag checks | `{ "mustBeFalseIn": ["production"] }` |
|
|
116
|
+
| `enum` | Restricted values | `{ "values": ["v1", "v2"] }` |
|
|
117
|
+
| `email` | Standard email format | `type: "email"` |
|
|
118
|
+
| `url` | Valid URL/URI structure | `type: "url"` |
|
|
119
|
+
| `regex` | Custom pattern matching | `{ "regex": "^sk_live_.*" }` |
|
|
116
120
|
|
|
117
121
|
## Contributing
|
|
118
122
|
|
|
119
|
-
We welcome contributions!
|
|
123
|
+
We welcome contributions! See the [issues](https://github.com/shashi089/env-drift-check/issues) for planned features or bug reports.
|
|
120
124
|
|
|
121
125
|
1. Fork the repository.
|
|
122
126
|
2. Create your feature branch (`git checkout -b feature/amazing-feature`).
|
|
@@ -124,6 +128,6 @@ We welcome contributions! Please follow these steps:
|
|
|
124
128
|
4. Push to the branch (`git push origin feature/amazing-feature`).
|
|
125
129
|
5. Open a Pull Request.
|
|
126
130
|
|
|
127
|
-
##
|
|
131
|
+
## License
|
|
128
132
|
|
|
129
|
-
|
|
133
|
+
MIT Ā© [Shashidhar Naik](https://github.com/shashi089)
|
package/dist/cli.js
CHANGED
|
@@ -6,70 +6,109 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const commander_1 = require("commander");
|
|
9
10
|
const envParser_1 = require("./engine/envParser");
|
|
10
11
|
const driftChecker_1 = require("./engine/driftChecker");
|
|
11
12
|
const consoleReporter_1 = require("./reporter/consoleReporter");
|
|
12
13
|
const interactive_1 = require("./engine/interactive");
|
|
13
14
|
const loadConfig_1 = require("./config/loadConfig");
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
const program = new commander_1.Command();
|
|
16
|
+
program
|
|
17
|
+
.name("env-drift-check")
|
|
18
|
+
.description("Interactive .env synchronizer and validator")
|
|
19
|
+
.version("0.1.5");
|
|
20
|
+
program
|
|
21
|
+
.command("check", { isDefault: true })
|
|
22
|
+
.description("Check for environment drift (default command)")
|
|
23
|
+
.argument("[file]", "Target .env file to check", ".env")
|
|
24
|
+
.option("-b, --base <reference>", "Reference .env file to check against (e.g., .env.example)")
|
|
25
|
+
.option("-i, --interactive", "Launch interactive setup wizard for missing keys")
|
|
26
|
+
.option("-s, --strict", "Fail with non-zero exit code if issues are found")
|
|
27
|
+
.option("-a, --all", "Check all .env* files in the current directory")
|
|
28
|
+
.action(async (file, options) => {
|
|
29
|
+
const config = (0, loadConfig_1.loadConfig)();
|
|
30
|
+
const basePath = path_1.default.resolve(options.base || config.baseEnv || ".env.example");
|
|
31
|
+
if (!fs_1.default.existsSync(basePath)) {
|
|
32
|
+
console.error(`Reference file missing: ${basePath}`);
|
|
33
|
+
process.exit(1);
|
|
31
34
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
35
|
+
const baseEnv = (0, envParser_1.parseEnv)(basePath);
|
|
36
|
+
async function runForFile(targetFile) {
|
|
37
|
+
const targetPath = path_1.default.resolve(targetFile);
|
|
38
|
+
if (!fs_1.default.existsSync(targetPath)) {
|
|
39
|
+
console.error(`File missing: ${targetFile}`);
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
console.log(`\n Checking ${path_1.default.basename(targetPath)} against ${path_1.default.basename(basePath)}...`);
|
|
43
|
+
const targetEnv = (0, envParser_1.parseEnv)(targetPath);
|
|
44
|
+
let result = (0, driftChecker_1.checkDrift)(baseEnv, targetEnv, config);
|
|
45
|
+
if (result.missing.length > 0 && options.interactive) {
|
|
46
|
+
const newValues = await (0, interactive_1.interactiveSetup)(result.missing, baseEnv, config);
|
|
47
|
+
// Merge new values into targetEnv
|
|
48
|
+
const updatedEnv = { ...targetEnv, ...newValues };
|
|
49
|
+
// Write back to file
|
|
50
|
+
const newContent = Object.entries(updatedEnv)
|
|
51
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
52
|
+
.join("\n");
|
|
53
|
+
fs_1.default.writeFileSync(targetPath, newContent);
|
|
54
|
+
console.log(`\n ā
Updated ${path_1.default.basename(targetPath)} with new values.`);
|
|
55
|
+
// Re-check drift
|
|
56
|
+
result = (0, driftChecker_1.checkDrift)(baseEnv, updatedEnv, config);
|
|
57
|
+
}
|
|
58
|
+
(0, consoleReporter_1.report)(result);
|
|
59
|
+
const hasIssues = result.missing.length || result.mismatches.length || result.errors.length;
|
|
60
|
+
return !hasIssues;
|
|
47
61
|
}
|
|
48
|
-
(0, consoleReporter_1.report)(result);
|
|
49
|
-
const hasIssues = result.missing.length || result.mismatches.length || result.errors.length;
|
|
50
|
-
return !hasIssues;
|
|
51
|
-
}
|
|
52
|
-
async function main() {
|
|
53
62
|
let allFiles = [];
|
|
54
|
-
if (
|
|
63
|
+
if (options.all) {
|
|
55
64
|
allFiles = fs_1.default.readdirSync(process.cwd())
|
|
56
65
|
.filter(f => f.startsWith(".env") && f !== path_1.default.basename(basePath));
|
|
57
66
|
}
|
|
58
67
|
else {
|
|
59
|
-
allFiles = [
|
|
68
|
+
allFiles = [file];
|
|
60
69
|
}
|
|
61
70
|
let overallSuccess = true;
|
|
62
|
-
for (const
|
|
63
|
-
const success = await runForFile(
|
|
71
|
+
for (const f of allFiles) {
|
|
72
|
+
const success = await runForFile(f);
|
|
64
73
|
if (!success)
|
|
65
74
|
overallSuccess = false;
|
|
66
75
|
}
|
|
67
|
-
if (strict && !overallSuccess) {
|
|
76
|
+
if (options.strict && !overallSuccess) {
|
|
68
77
|
console.error("\n Strict mode failed for one or more files");
|
|
69
78
|
process.exit(1);
|
|
70
79
|
}
|
|
71
|
-
}
|
|
72
|
-
main().catch(err => {
|
|
73
|
-
console.error(err);
|
|
74
|
-
process.exit(1);
|
|
75
80
|
});
|
|
81
|
+
program
|
|
82
|
+
.command("init")
|
|
83
|
+
.description("Initialize a new project with default configuration")
|
|
84
|
+
.action(() => {
|
|
85
|
+
const configPath = path_1.default.join(process.cwd(), "envwise.config.json");
|
|
86
|
+
const exampleEnvPath = path_1.default.join(process.cwd(), ".env.example");
|
|
87
|
+
if (fs_1.default.existsSync(configPath)) {
|
|
88
|
+
console.log("ā¹ļø envwise.config.json already exists.");
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const defaultConfig = {
|
|
92
|
+
baseEnv: ".env.example",
|
|
93
|
+
rules: {
|
|
94
|
+
PORT: {
|
|
95
|
+
type: "number",
|
|
96
|
+
min: 1024,
|
|
97
|
+
max: 65535,
|
|
98
|
+
description: "Application port"
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
fs_1.default.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2));
|
|
103
|
+
console.log("ā
Created envwise.config.json");
|
|
104
|
+
}
|
|
105
|
+
if (fs_1.default.existsSync(exampleEnvPath)) {
|
|
106
|
+
console.log("ā¹ļø .env.example already exists.");
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
fs_1.default.writeFileSync(exampleEnvPath, "PORT=3000\n");
|
|
110
|
+
console.log("ā
Created .env.example");
|
|
111
|
+
}
|
|
112
|
+
console.log("\nSetup complete! Run 'npx env-drift-check -i' to sync your .env file.");
|
|
113
|
+
});
|
|
114
|
+
program.parse(process.argv);
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import { Config } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Loads the project configuration from 'envwise.config.json' if it exists.
|
|
4
|
+
* Falls back to default configuration if no file is found.
|
|
5
|
+
*
|
|
6
|
+
* @returns The consolidated configuration object
|
|
7
|
+
*/
|
|
2
8
|
export declare function loadConfig(): Config;
|
|
@@ -10,6 +10,12 @@ const DEFAULT_CONFIG = {
|
|
|
10
10
|
baseEnv: ".env.example",
|
|
11
11
|
rules: {}
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Loads the project configuration from 'envwise.config.json' if it exists.
|
|
15
|
+
* Falls back to default configuration if no file is found.
|
|
16
|
+
*
|
|
17
|
+
* @returns The consolidated configuration object
|
|
18
|
+
*/
|
|
13
19
|
function loadConfig() {
|
|
14
20
|
const configPath = path_1.default.resolve("envwise.config.json");
|
|
15
21
|
if (!fs_1.default.existsSync(configPath)) {
|
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
import { DriftResult, Config } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Compares a base environment (template) against a target environment (actual)
|
|
4
|
+
* and returns the differences including missing keys, extra keys, and value mismatches.
|
|
5
|
+
*
|
|
6
|
+
* @param base - The record representing the template environment (e.g., .env.example)
|
|
7
|
+
* @param target - The record representing the actual environment (e.g., .env)
|
|
8
|
+
* @param config - Configuration object containing validation rules
|
|
9
|
+
* @returns An object containing the results of the drift check
|
|
10
|
+
*/
|
|
2
11
|
export declare function checkDrift(base: Record<string, string>, target: Record<string, string>, config: Config): DriftResult;
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checkDrift = checkDrift;
|
|
4
4
|
const validator_1 = require("./validator");
|
|
5
|
+
/**
|
|
6
|
+
* Compares a base environment (template) against a target environment (actual)
|
|
7
|
+
* and returns the differences including missing keys, extra keys, and value mismatches.
|
|
8
|
+
*
|
|
9
|
+
* @param base - The record representing the template environment (e.g., .env.example)
|
|
10
|
+
* @param target - The record representing the actual environment (e.g., .env)
|
|
11
|
+
* @param config - Configuration object containing validation rules
|
|
12
|
+
* @returns An object containing the results of the drift check
|
|
13
|
+
*/
|
|
5
14
|
function checkDrift(base, target, config) {
|
|
6
15
|
const result = {
|
|
7
16
|
missing: [],
|
|
@@ -1 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses a .env file from the given file system path.
|
|
3
|
+
* It handles comments, empty lines, and quoted values.
|
|
4
|
+
*
|
|
5
|
+
* @param path - The absolute or relative path to the .env file
|
|
6
|
+
* @returns A record containing key-value pairs of the environment variables
|
|
7
|
+
* @throws {Error} If the file does not exist
|
|
8
|
+
*/
|
|
1
9
|
export declare function parseEnv(path: string): Record<string, string>;
|
package/dist/engine/envParser.js
CHANGED
|
@@ -5,6 +5,14 @@ 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
|
+
/**
|
|
9
|
+
* Parses a .env file from the given file system path.
|
|
10
|
+
* It handles comments, empty lines, and quoted values.
|
|
11
|
+
*
|
|
12
|
+
* @param path - The absolute or relative path to the .env file
|
|
13
|
+
* @returns A record containing key-value pairs of the environment variables
|
|
14
|
+
* @throws {Error} If the file does not exist
|
|
15
|
+
*/
|
|
8
16
|
function parseEnv(path) {
|
|
9
17
|
if (!fs_1.default.existsSync(path)) {
|
|
10
18
|
throw new Error(`Env file not found: ${path}`);
|
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
import { Config } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Launches an interactive CLI wizard to help users fill in missing environment variables.
|
|
4
|
+
* Uses the 'prompts' package to collect user input with validation.
|
|
5
|
+
*
|
|
6
|
+
* @param missingKeys - An array of environment variable keys that are missing
|
|
7
|
+
* @param baseEnv - The template environment mapping
|
|
8
|
+
* @param config - The tool configuration containing validation rules
|
|
9
|
+
* @returns A promise that resolves to a record of the newly filled key-value pairs
|
|
10
|
+
*/
|
|
2
11
|
export declare function interactiveSetup(missingKeys: string[], baseEnv: Record<string, string>, config: Config): Promise<Record<string, string>>;
|
|
@@ -6,6 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.interactiveSetup = interactiveSetup;
|
|
7
7
|
const prompts_1 = __importDefault(require("prompts"));
|
|
8
8
|
const validator_1 = require("./validator");
|
|
9
|
+
/**
|
|
10
|
+
* Launches an interactive CLI wizard to help users fill in missing environment variables.
|
|
11
|
+
* Uses the 'prompts' package to collect user input with validation.
|
|
12
|
+
*
|
|
13
|
+
* @param missingKeys - An array of environment variable keys that are missing
|
|
14
|
+
* @param baseEnv - The template environment mapping
|
|
15
|
+
* @param config - The tool configuration containing validation rules
|
|
16
|
+
* @returns A promise that resolves to a record of the newly filled key-value pairs
|
|
17
|
+
*/
|
|
9
18
|
async function interactiveSetup(missingKeys, baseEnv, config) {
|
|
10
19
|
const newValues = {};
|
|
11
20
|
console.log("\nš Interactive Setup: Let's fill in the missing variables.\n");
|
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
import { Rule } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Validates a single environment variable value against a set of rules.
|
|
4
|
+
* Supports string length, number ranges, boolean flags, enums, emails, URLs, and custom regex.
|
|
5
|
+
*
|
|
6
|
+
* @param key - The name of the environment variable
|
|
7
|
+
* @param value - The value to validate
|
|
8
|
+
* @param rule - The validation rule configuration for this key
|
|
9
|
+
* @param env - The current environment (e.g., NODE_ENV) for conditional rules
|
|
10
|
+
* @returns A string containing the error message if validation fails, otherwise null
|
|
11
|
+
*/
|
|
2
12
|
export declare function validateValue(key: string, value: string, rule: Rule, env: string): string | null;
|
package/dist/engine/validator.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateValue = validateValue;
|
|
4
|
+
/**
|
|
5
|
+
* Validates a single environment variable value against a set of rules.
|
|
6
|
+
* Supports string length, number ranges, boolean flags, enums, emails, URLs, and custom regex.
|
|
7
|
+
*
|
|
8
|
+
* @param key - The name of the environment variable
|
|
9
|
+
* @param value - The value to validate
|
|
10
|
+
* @param rule - The validation rule configuration for this key
|
|
11
|
+
* @param env - The current environment (e.g., NODE_ENV) for conditional rules
|
|
12
|
+
* @returns A string containing the error message if validation fails, otherwise null
|
|
13
|
+
*/
|
|
4
14
|
function validateValue(key, value, rule, env) {
|
|
5
15
|
if (!value && rule.required !== false) {
|
|
6
16
|
return `${key} is required`;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,29 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a validation rule for an environment variable.
|
|
3
|
+
*/
|
|
1
4
|
export interface Rule {
|
|
5
|
+
/** The data type of the variable. Used for validation and CLI input prompts. */
|
|
2
6
|
type: "string" | "number" | "boolean" | "enum" | "email" | "url" | "regex";
|
|
7
|
+
/** Allowed values if the type is 'enum'. */
|
|
3
8
|
values?: string[];
|
|
9
|
+
/** Custom regular expression string if the type is 'regex'. */
|
|
4
10
|
regex?: string;
|
|
11
|
+
/** Minimum length (for strings) or minimum value (for numbers). */
|
|
5
12
|
min?: number;
|
|
13
|
+
/** Maximum length (for strings) or maximum value (for numbers). */
|
|
6
14
|
max?: number;
|
|
15
|
+
/** A helpful description displayed during interactive CLI setup. */
|
|
7
16
|
description?: string;
|
|
17
|
+
/** Environment(s) where this boolean must be false (useful for safety flags). */
|
|
8
18
|
mustBeFalseIn?: string;
|
|
19
|
+
/** Whether the variable is mandatory. Defaults to true. */
|
|
9
20
|
required?: boolean;
|
|
10
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Global configuration for the env-drift-check tool.
|
|
24
|
+
*/
|
|
11
25
|
export interface Config {
|
|
26
|
+
/** The template environment file to compare against (e.g., .env.example). */
|
|
12
27
|
baseEnv?: string;
|
|
28
|
+
/** A map of environment variable keys to their validation rules. */
|
|
13
29
|
rules?: Record<string, Rule>;
|
|
14
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Details of a mismatch between the base and target environment values.
|
|
33
|
+
*/
|
|
15
34
|
export interface ValueMismatch {
|
|
16
35
|
key: string;
|
|
17
36
|
expected: string;
|
|
18
37
|
actual: string;
|
|
19
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* The consolidated result of an environment drift check.
|
|
41
|
+
*/
|
|
20
42
|
export interface DriftResult {
|
|
43
|
+
/** Keys present in the template but missing in the target. */
|
|
21
44
|
missing: string[];
|
|
45
|
+
/** Keys present in the target but absent from the template. */
|
|
22
46
|
extra: string[];
|
|
47
|
+
/** Validation errors based on the defined rules. */
|
|
23
48
|
errors: {
|
|
24
49
|
key: string;
|
|
25
50
|
message: string;
|
|
26
51
|
}[];
|
|
52
|
+
/** Non-critical warnings. */
|
|
27
53
|
warnings: string[];
|
|
54
|
+
/** Values that differ between the template and target for the same key. */
|
|
28
55
|
mismatches: ValueMismatch[];
|
|
29
56
|
}
|
package/package.json
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "env-drift-check",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Interactive
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"description": "Interactive .env synchronizer and validator. Detect environment drift, sync missing variables, and enforce schema validation for seamless developer onboarding.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"env",
|
|
7
7
|
"dotenv",
|
|
8
8
|
"check-env",
|
|
9
9
|
"dotenv-safe",
|
|
10
|
+
"env-drift-check",
|
|
10
11
|
"environment-variables",
|
|
12
|
+
"env-validation",
|
|
11
13
|
"config",
|
|
12
14
|
"validation",
|
|
13
15
|
"interactive",
|
|
14
16
|
"setup",
|
|
15
17
|
"onboarding",
|
|
16
18
|
"drift",
|
|
17
|
-
"checker"
|
|
19
|
+
"checker",
|
|
20
|
+
"cli-tool",
|
|
21
|
+
"dx",
|
|
22
|
+
"env-sync",
|
|
23
|
+
"security",
|
|
24
|
+
"workflow"
|
|
18
25
|
],
|
|
19
26
|
"author": "Shashidhar Naik",
|
|
20
27
|
"license": "MIT",
|