nero-env 0.1.3 → 0.1.5
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/dist/cli/command.js +17 -20
- package/dist/cli/options.js +10 -10
- package/dist/core/compareEnv.js +1 -4
- package/dist/core/readEnv.js +3 -9
- package/dist/core/types.js +1 -2
- package/dist/core/validateEnv.js +1 -4
- package/dist/index.js +4 -6
- package/dist/meta.js +4 -5
- package/dist/output/formatter.js +1 -4
- package/dist/output/printer.js +16 -22
- package/dist/output/types.js +1 -2
- package/dist/update.js +6 -12
- package/package.json +2 -1
- package/dist/cli/help.js +0 -1
package/dist/cli/command.js
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const printer_1 = require("../output/printer");
|
|
11
|
-
function run() {
|
|
12
|
-
const options = (0, options_1.parseOptions)();
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { parseOptions } from "./options.js";
|
|
3
|
+
import { readEnvFile } from "../core/readEnv.js";
|
|
4
|
+
import { compareEnv } from "../core/compareEnv.js";
|
|
5
|
+
import { validateEnv } from "../core/validateEnv.js";
|
|
6
|
+
import { formatEnvReport } from "../output/formatter.js";
|
|
7
|
+
import { printReport } from "../output/printer.js";
|
|
8
|
+
export function run() {
|
|
9
|
+
const options = parseOptions();
|
|
13
10
|
const targetPath = options.projectPath;
|
|
14
|
-
const envFilePath =
|
|
15
|
-
const exampleFilePath =
|
|
16
|
-
const actualEnv =
|
|
17
|
-
const exampleEnv =
|
|
18
|
-
const report =
|
|
11
|
+
const envFilePath = join(targetPath, ".env");
|
|
12
|
+
const exampleFilePath = join(targetPath, ".env.example");
|
|
13
|
+
const actualEnv = readEnvFile(envFilePath);
|
|
14
|
+
const exampleEnv = readEnvFile(exampleFilePath);
|
|
15
|
+
const report = compareEnv(exampleEnv, actualEnv);
|
|
19
16
|
// Extra validation layer
|
|
20
|
-
const emptyKeys =
|
|
17
|
+
const emptyKeys = validateEnv(actualEnv);
|
|
21
18
|
if (emptyKeys.length > 0) {
|
|
22
19
|
report.issues.empty = emptyKeys;
|
|
23
20
|
report.hasIssues = true;
|
|
24
21
|
}
|
|
25
|
-
const formattedReport =
|
|
26
|
-
|
|
22
|
+
const formattedReport = formatEnvReport(report);
|
|
23
|
+
printReport(formattedReport);
|
|
27
24
|
if (formattedReport.hasIssues) {
|
|
28
25
|
process.exit(1);
|
|
29
26
|
}
|
package/dist/cli/options.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
function parseOptions() {
|
|
7
|
-
const program = new commander_1.Command();
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { CLI_NAME, CLI_VERSION } from "../meta.js";
|
|
4
|
+
export function parseOptions() {
|
|
5
|
+
const program = new Command();
|
|
8
6
|
program
|
|
9
|
-
.name(
|
|
7
|
+
.name(CLI_NAME)
|
|
10
8
|
.description("Validate and compare .env files")
|
|
11
|
-
.
|
|
9
|
+
.version(CLI_VERSION, "-v, --version", "output the version number")
|
|
10
|
+
.option("-p, --path <path>", "Path to the project directory (defaults to current working directory)", process.cwd())
|
|
11
|
+
.helpOption("-h, --help", "display help for command")
|
|
12
12
|
.parse(process.argv);
|
|
13
13
|
const opts = program.opts();
|
|
14
14
|
return {
|
|
15
|
-
projectPath:
|
|
15
|
+
projectPath: resolve(opts.path),
|
|
16
16
|
};
|
|
17
17
|
}
|
package/dist/core/compareEnv.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compareEnv = compareEnv;
|
|
4
|
-
function compareEnv(exampleEnv, actualEnv) {
|
|
1
|
+
export function compareEnv(exampleEnv, actualEnv) {
|
|
5
2
|
const expectedKeys = new Set(Object.keys(exampleEnv));
|
|
6
3
|
const actualKeys = new Set(Object.keys(actualEnv));
|
|
7
4
|
const issues = {
|
package/dist/core/readEnv.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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) {
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
export function readEnvFile(filePath) {
|
|
9
3
|
const envVariables = {};
|
|
10
4
|
try {
|
|
11
|
-
const fileContent =
|
|
5
|
+
const fileContent = fs.readFileSync(filePath, "utf8");
|
|
12
6
|
if (!fileContent) {
|
|
13
7
|
return envVariables;
|
|
14
8
|
}
|
package/dist/core/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/core/validateEnv.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateEnv = validateEnv;
|
|
4
|
-
function validateEnv(actualEnv) {
|
|
1
|
+
export function validateEnv(actualEnv) {
|
|
5
2
|
const emptyKeys = [];
|
|
6
3
|
for (const [key, value] of Object.entries(actualEnv)) {
|
|
7
4
|
if (value === "") {
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const command_1 = require("./cli/command");
|
|
5
|
-
const update_1 = require("./update");
|
|
2
|
+
import { run } from "./cli/command.js";
|
|
3
|
+
import { notifyUpdate } from "./update.js";
|
|
6
4
|
try {
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
notifyUpdate();
|
|
6
|
+
run();
|
|
9
7
|
}
|
|
10
8
|
catch (err) {
|
|
11
9
|
console.error("Unexpected error:", err);
|
package/dist/meta.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.CLI_VERSION = "0.1.0";
|
|
1
|
+
// src/meta.ts
|
|
2
|
+
import pkg from "../package.json" with { type: "json" };
|
|
3
|
+
export const CLI_NAME = pkg.name;
|
|
4
|
+
export const CLI_VERSION = pkg.version;
|
package/dist/output/formatter.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatEnvReport = formatEnvReport;
|
|
4
|
-
function formatEnvReport(report) {
|
|
1
|
+
export function formatEnvReport(report) {
|
|
5
2
|
const sections = [];
|
|
6
3
|
const { missing, unused, empty } = report.issues;
|
|
7
4
|
if (missing.length > 0) {
|
package/dist/output/printer.js
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
|
|
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"));
|
|
1
|
+
import chalk from "chalk";
|
|
8
2
|
const icons = {
|
|
9
|
-
error:
|
|
10
|
-
warning:
|
|
11
|
-
success:
|
|
3
|
+
error: chalk.red("❌"),
|
|
4
|
+
warning: chalk.yellow("⚠️"),
|
|
5
|
+
success: chalk.green("✅"),
|
|
12
6
|
};
|
|
13
|
-
function printReport(report) {
|
|
7
|
+
export function printReport(report) {
|
|
14
8
|
// Title
|
|
15
|
-
console.log(
|
|
16
|
-
console.log(
|
|
9
|
+
console.log(chalk.bold("Nero Env Check"));
|
|
10
|
+
console.log(chalk.dim("─────────────\n"));
|
|
17
11
|
// Success case
|
|
18
12
|
if (!report.hasIssues || report.sections.length === 0) {
|
|
19
|
-
console.log(`${icons.success} ${
|
|
13
|
+
console.log(`${icons.success} ${chalk.green("No environment issues found")}`);
|
|
20
14
|
printSummary(0, 0);
|
|
21
15
|
return;
|
|
22
16
|
}
|
|
@@ -38,27 +32,27 @@ function printReport(report) {
|
|
|
38
32
|
function printSection(section) {
|
|
39
33
|
const icon = icons[section.severity];
|
|
40
34
|
if (section.source === ".env") {
|
|
41
|
-
console.log(`${icon} ${
|
|
35
|
+
console.log(`${icon} ${chalk.bold(section.title)} ${chalk.dim(`(${section.source})`)}`);
|
|
42
36
|
}
|
|
43
37
|
else {
|
|
44
|
-
console.log(`${icon} ${
|
|
38
|
+
console.log(`${icon} ${chalk.bold(section.title)} ${chalk.dim(`(not declared in ${section.source})`)}`);
|
|
45
39
|
}
|
|
46
40
|
for (const item of section.items) {
|
|
47
|
-
console.log(` ${
|
|
41
|
+
console.log(` ${chalk.dim("•")} ${chalk.cyan(item)}`);
|
|
48
42
|
}
|
|
49
43
|
}
|
|
50
44
|
function printSummary(errors, warnings) {
|
|
51
|
-
console.log(
|
|
45
|
+
console.log(chalk.dim("─────────────"));
|
|
52
46
|
if (errors === 0 && warnings === 0) {
|
|
53
|
-
console.log(
|
|
47
|
+
console.log(chalk.dim("Summary: ") + chalk.green("No issues found"));
|
|
54
48
|
return;
|
|
55
49
|
}
|
|
56
50
|
const parts = [];
|
|
57
51
|
if (errors > 0) {
|
|
58
|
-
parts.push(
|
|
52
|
+
parts.push(chalk.red(`${errors} error${errors > 1 ? "s" : ""}`));
|
|
59
53
|
}
|
|
60
54
|
if (warnings > 0) {
|
|
61
|
-
parts.push(
|
|
55
|
+
parts.push(chalk.yellow(`${warnings} warning${warnings > 1 ? "s" : ""}`));
|
|
62
56
|
}
|
|
63
|
-
console.log(
|
|
57
|
+
console.log(chalk.dim("Summary: ") + parts.join(chalk.dim(", ")));
|
|
64
58
|
}
|
package/dist/output/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/update.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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)({
|
|
1
|
+
import updateNotifier from "update-notifier";
|
|
2
|
+
import { CLI_NAME, CLI_VERSION } from "./meta.js";
|
|
3
|
+
export function notifyUpdate() {
|
|
4
|
+
updateNotifier({
|
|
11
5
|
pkg: {
|
|
12
|
-
name:
|
|
13
|
-
version:
|
|
6
|
+
name: CLI_NAME,
|
|
7
|
+
version: CLI_VERSION,
|
|
14
8
|
},
|
|
15
9
|
updateCheckInterval: 1000 * 60 * 60 * 24,
|
|
16
10
|
}).notify({ isGlobal: true });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nero-env",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Validate and compare .env files to catch missing, empty, and unused variables.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@types/node": "^25.0.3",
|
|
38
38
|
"@types/update-notifier": "^6.0.8",
|
|
39
39
|
"ts-node": "^10.9.2",
|
|
40
|
+
"tsx": "^4.21.0",
|
|
40
41
|
"typescript": "^5.9.3"
|
|
41
42
|
},
|
|
42
43
|
"dependencies": {
|
package/dist/cli/help.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|