@forz/dev-toolkit
Version:
đ§° Developer Toolkit CLI for Git, env, and project automation by Alfonso Pisicchio
31 lines (23 loc) âĸ 936 B
JavaScript
import fs from "fs";
import chalk from "chalk";
import dotenv from "dotenv";
export function envCheck() {
const envFile = ".env";
const exampleFile = ".env.example";
if (!fs.existsSync(exampleFile)) {
console.log(chalk.red("â Missing .env.example file."));
process.exit(1);
}
const envVars = dotenv.parse(fs.readFileSync(envFile, "utf-8"));
const exampleVars = dotenv.parse(fs.readFileSync(exampleFile, "utf-8"));
const missing = Object.keys(exampleVars).filter(k => !(k in envVars));
const extra = Object.keys(envVars).filter(k => !(k in exampleVars));
if (missing.length === 0 && extra.length === 0) {
console.log(chalk.green("â
Environment variables are consistent!"));
return;
}
if (missing.length > 0)
console.log(chalk.yellow("â ī¸ Missing variables:"), missing.join(", "));
if (extra.length > 0)
console.log(chalk.cyan("âšī¸ Extra variables:"), extra.join(", "));
}