nero-env 0.1.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 +47 -0
- package/dist/cli/command.js +30 -0
- package/dist/cli/help.js +1 -0
- package/dist/cli/options.js +17 -0
- package/dist/core/compareEnv.js +37 -0
- package/dist/core/readEnv.js +36 -0
- package/dist/core/types.js +2 -0
- package/dist/core/validateEnv.js +12 -0
- package/dist/index.js +13 -0
- package/dist/meta.js +5 -0
- package/dist/output/formatter.js +35 -0
- package/dist/output/printer.js +64 -0
- package/dist/output/types.js +2 -0
- package/dist/update.js +17 -0
- package/package.json +27 -0
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# nero-env
|
|
2
|
+
|
|
3
|
+
A simple CLI tool to validate environment variables in a project.
|
|
4
|
+
|
|
5
|
+
nero-env compares your active .env file with .env.example and reports:
|
|
6
|
+
|
|
7
|
+
- missing variables
|
|
8
|
+
- empty values
|
|
9
|
+
- unused variables
|
|
10
|
+
|
|
11
|
+
Clear output. No configuration. Safe by default.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g nero-env
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
nero-env
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Check a specific project:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
nero-env --path ./apps/api
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
<!-- Fail on issues (useful for CI):
|
|
32
|
+
```bash
|
|
33
|
+
nero-env --strict
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Use a specific env file:
|
|
37
|
+
```bash
|
|
38
|
+
nero-env --env development
|
|
39
|
+
``` -->
|
|
40
|
+
|
|
41
|
+
## What it checks
|
|
42
|
+
|
|
43
|
+
- **Missing** → defined in .env.example but not in .env
|
|
44
|
+
- **Empty** → defined but has no value
|
|
45
|
+
- **Unused** → present in .env but not declared in .env.example
|
|
46
|
+
|
|
47
|
+
Output clearly shows which file needs fixing.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.run = run;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const options_1 = require("./options");
|
|
6
|
+
const readEnv_1 = require("../core/readEnv");
|
|
7
|
+
const compareEnv_1 = require("../core/compareEnv");
|
|
8
|
+
const validateEnv_1 = require("../core/validateEnv");
|
|
9
|
+
const formatter_1 = require("../output/formatter");
|
|
10
|
+
const printer_1 = require("../output/printer");
|
|
11
|
+
function run() {
|
|
12
|
+
const options = (0, options_1.parseOptions)();
|
|
13
|
+
const targetPath = options.projectPath;
|
|
14
|
+
const envFilePath = (0, node_path_1.join)(targetPath, ".env");
|
|
15
|
+
const exampleFilePath = (0, node_path_1.join)(targetPath, ".env.example");
|
|
16
|
+
const actualEnv = (0, readEnv_1.readEnvFile)(envFilePath);
|
|
17
|
+
const exampleEnv = (0, readEnv_1.readEnvFile)(exampleFilePath);
|
|
18
|
+
const report = (0, compareEnv_1.compareEnv)(exampleEnv, actualEnv);
|
|
19
|
+
// Extra validation layer
|
|
20
|
+
const emptyKeys = (0, validateEnv_1.validateEnv)(actualEnv);
|
|
21
|
+
if (emptyKeys.length > 0) {
|
|
22
|
+
report.issues.empty = emptyKeys;
|
|
23
|
+
report.hasIssues = true;
|
|
24
|
+
}
|
|
25
|
+
const formattedReport = (0, formatter_1.formatEnvReport)(report);
|
|
26
|
+
(0, printer_1.printReport)(formattedReport);
|
|
27
|
+
if (formattedReport.hasIssues) {
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
}
|
package/dist/cli/help.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseOptions = parseOptions;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
function parseOptions() {
|
|
7
|
+
const program = new commander_1.Command();
|
|
8
|
+
program
|
|
9
|
+
.name("nero-env")
|
|
10
|
+
.description("Validate and compare .env files")
|
|
11
|
+
.option("-p, --path <path>", "Path to the project directory", process.cwd())
|
|
12
|
+
.parse(process.argv);
|
|
13
|
+
const opts = program.opts();
|
|
14
|
+
return {
|
|
15
|
+
projectPath: (0, node_path_1.resolve)(opts.path),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compareEnv = compareEnv;
|
|
4
|
+
function compareEnv(exampleEnv, actualEnv) {
|
|
5
|
+
const expectedKeys = new Set(Object.keys(exampleEnv));
|
|
6
|
+
const actualKeys = new Set(Object.keys(actualEnv));
|
|
7
|
+
const issues = {
|
|
8
|
+
missing: [],
|
|
9
|
+
unused: [],
|
|
10
|
+
empty: [],
|
|
11
|
+
};
|
|
12
|
+
// Missing: expected but not provided
|
|
13
|
+
for (const key of expectedKeys) {
|
|
14
|
+
if (!actualKeys.has(key)) {
|
|
15
|
+
issues.missing.push(key);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
// Unused: provided but not expected
|
|
19
|
+
for (const key of actualKeys) {
|
|
20
|
+
if (!expectedKeys.has(key)) {
|
|
21
|
+
issues.unused.push(key);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// Empty: provided but value is empty string
|
|
25
|
+
for (const [key, value] of Object.entries(actualEnv)) {
|
|
26
|
+
if (value === "") {
|
|
27
|
+
issues.empty.push(key);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const hasIssues = issues.missing.length > 0 ||
|
|
31
|
+
issues.unused.length > 0 ||
|
|
32
|
+
issues.empty.length > 0;
|
|
33
|
+
return {
|
|
34
|
+
issues,
|
|
35
|
+
hasIssues,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.readEnvFile = readEnvFile;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
function readEnvFile(filePath) {
|
|
9
|
+
const envVariables = {};
|
|
10
|
+
try {
|
|
11
|
+
const fileContent = node_fs_1.default.readFileSync(filePath, "utf8");
|
|
12
|
+
if (!fileContent) {
|
|
13
|
+
return envVariables;
|
|
14
|
+
}
|
|
15
|
+
const lines = fileContent.split("\n");
|
|
16
|
+
for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
|
|
17
|
+
const rawLine = lines[lineIndex].trim();
|
|
18
|
+
// Skip empty lines and comments
|
|
19
|
+
if (!rawLine || rawLine.startsWith("#")) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const equalsIndex = rawLine.indexOf("=");
|
|
23
|
+
// Skip malformed lines (no '=')
|
|
24
|
+
if (equalsIndex === -1) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const key = rawLine.slice(0, equalsIndex).trim();
|
|
28
|
+
const value = rawLine.slice(equalsIndex + 1).trim();
|
|
29
|
+
envVariables[key] = value;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return envVariables;
|
|
34
|
+
}
|
|
35
|
+
return envVariables;
|
|
36
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateEnv = validateEnv;
|
|
4
|
+
function validateEnv(actualEnv) {
|
|
5
|
+
const emptyKeys = [];
|
|
6
|
+
for (const [key, value] of Object.entries(actualEnv)) {
|
|
7
|
+
if (value === "") {
|
|
8
|
+
emptyKeys.push(key);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return emptyKeys;
|
|
12
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const command_1 = require("./cli/command");
|
|
5
|
+
const update_1 = require("./update");
|
|
6
|
+
try {
|
|
7
|
+
(0, update_1.notifyUpdate)(); // non-blocking, safe, cached
|
|
8
|
+
(0, command_1.run)();
|
|
9
|
+
}
|
|
10
|
+
catch (err) {
|
|
11
|
+
console.error("Unexpected error:", err);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
package/dist/meta.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatEnvReport = formatEnvReport;
|
|
4
|
+
function formatEnvReport(report) {
|
|
5
|
+
const sections = [];
|
|
6
|
+
const { missing, unused, empty } = report.issues;
|
|
7
|
+
if (missing.length > 0) {
|
|
8
|
+
sections.push({
|
|
9
|
+
title: "Missing variables",
|
|
10
|
+
items: missing,
|
|
11
|
+
severity: "error",
|
|
12
|
+
source: ".env",
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
if (unused.length > 0) {
|
|
16
|
+
sections.push({
|
|
17
|
+
title: "Unused variables",
|
|
18
|
+
items: unused,
|
|
19
|
+
severity: "warning",
|
|
20
|
+
source: ".env.example",
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (empty.length > 0) {
|
|
24
|
+
sections.push({
|
|
25
|
+
title: "Empty variables",
|
|
26
|
+
items: empty,
|
|
27
|
+
severity: "warning",
|
|
28
|
+
source: ".env",
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
sections,
|
|
33
|
+
hasIssues: report.hasIssues,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.printReport = printReport;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const icons = {
|
|
9
|
+
error: chalk_1.default.red("❌"),
|
|
10
|
+
warning: chalk_1.default.yellow("⚠️"),
|
|
11
|
+
success: chalk_1.default.green("✅"),
|
|
12
|
+
};
|
|
13
|
+
function printReport(report) {
|
|
14
|
+
// Title
|
|
15
|
+
console.log(chalk_1.default.bold("Nero Env Check"));
|
|
16
|
+
console.log(chalk_1.default.dim("─────────────\n"));
|
|
17
|
+
// Success case
|
|
18
|
+
if (!report.hasIssues || report.sections.length === 0) {
|
|
19
|
+
console.log(`${icons.success} ${chalk_1.default.green("No environment issues found")}`);
|
|
20
|
+
printSummary(0, 0);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
let errorCount = 0;
|
|
24
|
+
let warningCount = 0;
|
|
25
|
+
// Issue sections
|
|
26
|
+
for (const section of report.sections) {
|
|
27
|
+
printSection(section);
|
|
28
|
+
console.log(); // spacing
|
|
29
|
+
if (section.severity === "error") {
|
|
30
|
+
errorCount += section.items.length;
|
|
31
|
+
}
|
|
32
|
+
else if (section.severity === "warning") {
|
|
33
|
+
warningCount += section.items.length;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
printSummary(errorCount, warningCount);
|
|
37
|
+
}
|
|
38
|
+
function printSection(section) {
|
|
39
|
+
const icon = icons[section.severity];
|
|
40
|
+
if (section.source === ".env") {
|
|
41
|
+
console.log(`${icon} ${chalk_1.default.bold(section.title)} ${chalk_1.default.dim(`(${section.source})`)}`);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
console.log(`${icon} ${chalk_1.default.bold(section.title)} ${chalk_1.default.dim(`(not declared in ${section.source})`)}`);
|
|
45
|
+
}
|
|
46
|
+
for (const item of section.items) {
|
|
47
|
+
console.log(` ${chalk_1.default.dim("•")} ${chalk_1.default.cyan(item)}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function printSummary(errors, warnings) {
|
|
51
|
+
console.log(chalk_1.default.dim("─────────────"));
|
|
52
|
+
if (errors === 0 && warnings === 0) {
|
|
53
|
+
console.log(chalk_1.default.dim("Summary: ") + chalk_1.default.green("No issues found"));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const parts = [];
|
|
57
|
+
if (errors > 0) {
|
|
58
|
+
parts.push(chalk_1.default.red(`${errors} error${errors > 1 ? "s" : ""}`));
|
|
59
|
+
}
|
|
60
|
+
if (warnings > 0) {
|
|
61
|
+
parts.push(chalk_1.default.yellow(`${warnings} warning${warnings > 1 ? "s" : ""}`));
|
|
62
|
+
}
|
|
63
|
+
console.log(chalk_1.default.dim("Summary: ") + parts.join(chalk_1.default.dim(", ")));
|
|
64
|
+
}
|
package/dist/update.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.notifyUpdate = notifyUpdate;
|
|
7
|
+
const update_notifier_1 = __importDefault(require("update-notifier"));
|
|
8
|
+
const meta_1 = require("./meta");
|
|
9
|
+
function notifyUpdate() {
|
|
10
|
+
(0, update_notifier_1.default)({
|
|
11
|
+
pkg: {
|
|
12
|
+
name: meta_1.CLI_NAME,
|
|
13
|
+
version: meta_1.CLI_VERSION,
|
|
14
|
+
},
|
|
15
|
+
updateCheckInterval: 1000 * 60 * 60 * 24,
|
|
16
|
+
}).notify({ isGlobal: true });
|
|
17
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nero-env",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Validate and compare .env files",
|
|
5
|
+
"bin": {
|
|
6
|
+
"nero-env": "dist/index.js"
|
|
7
|
+
},
|
|
8
|
+
"files": ["dist"],
|
|
9
|
+
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"dev": "ts-node src/index.ts"
|
|
13
|
+
},
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"packageManager": "pnpm@10.17.1",
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/node": "^25.0.3",
|
|
18
|
+
"@types/update-notifier": "^6.0.8",
|
|
19
|
+
"ts-node": "^10.9.2",
|
|
20
|
+
"typescript": "^5.9.3"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"chalk": "^5.6.2",
|
|
24
|
+
"commander": "^14.0.2",
|
|
25
|
+
"update-notifier": "^7.3.1"
|
|
26
|
+
}
|
|
27
|
+
}
|