dotenv-diff 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.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # dotenv diff cli to compare .env with .env.example
package/dist/cli.js ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+ import path from 'path';
3
+ import fs from 'fs';
4
+ import chalk from 'chalk';
5
+ import { parseEnvFile } from './lib/parseEnv.js';
6
+ import { diffEnv } from './lib/diffEnv.js';
7
+ const envPath = path.resolve(process.cwd(), '.env');
8
+ const examplePath = path.resolve(process.cwd(), '.env.example');
9
+ if (!fs.existsSync(envPath)) {
10
+ console.error(chalk.red('❌ Error: .env file is missing in the project root.'));
11
+ process.exit(1);
12
+ }
13
+ if (!fs.existsSync(examplePath)) {
14
+ console.error(chalk.red('❌ Error: .env.example file is missing in the project root.'));
15
+ process.exit(1);
16
+ }
17
+ console.log(chalk.bold('🔍 Comparing .env and .env.example...'));
18
+ const current = parseEnvFile(envPath);
19
+ const example = parseEnvFile(examplePath);
20
+ const diff = diffEnv(current, example);
21
+ // Find tomme variabler i .env
22
+ const emptyKeys = Object.entries(current)
23
+ .filter(([key, value]) => value.trim() === '')
24
+ .map(([key]) => key);
25
+ let hasWarnings = false;
26
+ if (diff.missing.length === 0 && diff.extra.length === 0 && emptyKeys.length === 0) {
27
+ console.log(chalk.green('✅ All keys match! Your .env file is valid.'));
28
+ process.exit(0);
29
+ }
30
+ if (diff.missing.length > 0) {
31
+ console.log(chalk.red('\n❌ Missing keys in .env:'));
32
+ diff.missing.forEach((key) => console.log(chalk.red(` - ${key}`)));
33
+ }
34
+ if (diff.extra.length > 0) {
35
+ console.log(chalk.yellow('\n⚠️ Extra keys in .env (not defined in .env.example):'));
36
+ diff.extra.forEach((key) => console.log(chalk.yellow(` - ${key}`)));
37
+ }
38
+ if (emptyKeys.length > 0) {
39
+ hasWarnings = true;
40
+ console.log(chalk.yellow('\n⚠️ The following keys in .env have no value (empty):'));
41
+ emptyKeys.forEach((key) => console.log(chalk.yellow(` - ${key}`)));
42
+ }
43
+ process.exit(diff.missing.length > 0 ? 1 : hasWarnings ? 0 : 0);
@@ -0,0 +1,2 @@
1
+ export { parseEnvFile } from './lib/parseEnv.js';
2
+ export { diffEnv, type DiffResult } from './lib/diffEnv.js';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { parseEnvFile } from './lib/parseEnv.js';
2
+ export { diffEnv } from './lib/diffEnv.js';
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "dotenv-diff",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "description": "A small CLI and library to find differences between .env and .env.example files.",
6
+ "bin": {
7
+ "dotenv-diff": "dist/cli.js"
8
+ },
9
+ "main": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "files": [
12
+ "dist/cli.js",
13
+ "dist/index.js",
14
+ "dist/index.d.ts",
15
+ "README.md"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "dev": "vitest --watch",
20
+ "test": "vitest",
21
+ "start": "node dist/cli.js"
22
+ },
23
+ "author": "Chrilleweb",
24
+ "license": "MIT",
25
+ "keywords": [
26
+ "dotenv",
27
+ "env",
28
+ "dotenv-diff",
29
+ "cli",
30
+ "compare",
31
+ "environment variables",
32
+ "dotenv validator"
33
+ ],
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/Chrilleweb/dotenv-diff.git"
37
+ },
38
+ "engines": {
39
+ "node": ">=14.0.0"
40
+ },
41
+ "dependencies": {
42
+ "chalk": "^5.4.1"
43
+ },
44
+ "devDependencies": {
45
+ "@types/node": "^20.0.0",
46
+ "typescript": "^5.2.0",
47
+ "vitest": "^3.2.0"
48
+ }
49
+ }