env-latest 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/.env +1 -0
- package/.env.example +2 -0
- package/index.js +59 -0
- package/package.json +18 -0
package/.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
DB_HOST=127.0.0.1
|
package/.env.example
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const dotenv = require('dotenv');
|
|
6
|
+
|
|
7
|
+
// ANSI sequence for colors
|
|
8
|
+
const colors = {
|
|
9
|
+
red: '\x1b[31m',
|
|
10
|
+
green: '\x1b[32m',
|
|
11
|
+
yellow: '\x1b[33m',
|
|
12
|
+
blue: '\x1b[34m',
|
|
13
|
+
reset: '\x1b[0m',
|
|
14
|
+
bold: '\x1b[1m'
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function printPrefix() {
|
|
18
|
+
return `${colors.bold}${colors.blue}[env-latest]${colors.reset}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function runAudit() {
|
|
22
|
+
const cwd = process.cwd();
|
|
23
|
+
const exampleEnvPath = path.join(cwd, '.env.example');
|
|
24
|
+
const localEnvPath = path.join(cwd, '.env');
|
|
25
|
+
|
|
26
|
+
if (!fs.existsSync(exampleEnvPath)) {
|
|
27
|
+
console.log(`${printPrefix()} ℹ️ No .env.example found. Skipping audit.`);
|
|
28
|
+
process.exit(0);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const exampleEnvBuf = fs.readFileSync(exampleEnvPath);
|
|
32
|
+
const exampleKeys = Object.keys(dotenv.parse(exampleEnvBuf));
|
|
33
|
+
|
|
34
|
+
let localKeys = [];
|
|
35
|
+
if (fs.existsSync(localEnvPath)) {
|
|
36
|
+
const localEnvBuf = fs.readFileSync(localEnvPath);
|
|
37
|
+
localKeys = Object.keys(dotenv.parse(localEnvBuf));
|
|
38
|
+
} else {
|
|
39
|
+
console.log(`${printPrefix()} ${colors.yellow}⚠️ No .env file found! You might need to create one based on .env.example.${colors.reset}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const missingKeys = exampleKeys.filter(key => !localKeys.includes(key));
|
|
43
|
+
|
|
44
|
+
if (missingKeys.length === 0) {
|
|
45
|
+
console.log(`${printPrefix()} ${colors.green}✅ All environment variables are synced!${colors.reset}`);
|
|
46
|
+
process.exit(0);
|
|
47
|
+
} else {
|
|
48
|
+
console.error(`${printPrefix()} ${colors.red}❌ Error: Missing environment variables in your .env file:${colors.reset}`);
|
|
49
|
+
missingKeys.forEach(key => {
|
|
50
|
+
console.error(` ${colors.red}- ${key}${colors.reset}`);
|
|
51
|
+
});
|
|
52
|
+
console.error(`\n${colors.yellow}Please add these to your .env file so the application can run properly.${colors.reset}\n`);
|
|
53
|
+
|
|
54
|
+
// Exit with an error code to fail CI or pre-commit hooks
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
runAudit();
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "env-latest",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
|
+
},
|
|
8
|
+
"keywords": [],
|
|
9
|
+
"author": "",
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"description": "CLI tool to check if all variables from .env.example are present in .env",
|
|
12
|
+
"bin": {
|
|
13
|
+
"env-latest": "./index.js"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"dotenv": "^17.3.1"
|
|
17
|
+
}
|
|
18
|
+
}
|