refactor: remove check-env-vars.js and update lint script to streamline environment checks

This commit is contained in:
Marco Pedone 2025-10-20 16:42:43 +02:00
parent 8a17863c85
commit f904500e2d
4 changed files with 4 additions and 55 deletions

View file

@ -1,50 +0,0 @@
const fs = require("node:fs");
const YAML = require("yaml");
const ciFilepath = ".github/workflows/ci.yml";
const envFilepath = "src/env.mjs";
const ignoreEnvs = ["NODE_ENV", "SKIP_ENV_VALIDATION"];
// ANSI escape codes for colors
const colors = {
red: "\x1b[31m%s\x1b[0m",
green: "\x1b[32m%s\x1b[0m",
yellow: "\x1b[33m%s\x1b[0m",
};
console.log();
console.log(colors.yellow, "Environment variables checker:");
// Read CI file content
try {
const ciContent = fs.readFileSync(ciFilepath, "utf8");
const ciData = YAML.parse(ciContent);
// Read env file content
const envContent = fs.readFileSync(envFilepath, "utf8");
const envRegex = /process\.env\.([A-Z_0-9]+)/g;
const declaredEnvs = [];
let match = envRegex.exec(envContent);
while (match !== null) {
declaredEnvs.push(match[1]);
match = envRegex.exec(envContent); // Re-assign at the end of the loop
}
// Remove ignored environment variables from the list of declared environment variables
const filteredEnvs = declaredEnvs.filter((env) => !ignoreEnvs.includes(env));
// Check for missing env variables in CI file
const missingEnvs = filteredEnvs.filter((env) => !ciData.env[env]);
if (missingEnvs.length > 0) {
console.error(
colors.red,
`Missing environment variables in ${ciFilepath}: ${missingEnvs.join(", ")}`,
);
} else {
console.log(colors.green, "No missing environment variables found.");
}
} catch (error) {
console.error(colors.red, `Error processing files: ${error.message}`);
}

View file

@ -1,6 +1,6 @@
console.log( console.log(
"\x1b[33m%s\x1b[0m", "\x1b[33m%s\x1b[0m",
` `
_ _ _ _ _ _
| | (_) | | | | (_) | |
| | _ _ __ | |_ | | _ _ __ | |_
@ -8,6 +8,6 @@ console.log(
| |____| | | | | |_ | |____| | | | | |_
\\_____/|_|_| |_|\\__| \\_____/|_|_| |_|\\__|
🔍 Linting and Env Checks... 🔍 Linting ...
`, `,
); );

View file

@ -9,7 +9,7 @@
"email": "cross-env NEXT_PUBLIC_BASE_URL='https://localhost:3000' email dev --port 3500", "email": "cross-env NEXT_PUBLIC_BASE_URL='https://localhost:3000' email dev --port 3500",
"idev": "cross-env NODE_OPTIONS='--inspect' next dev --turbopack", "idev": "cross-env NODE_OPTIONS='--inspect' next dev --turbopack",
"knip": "knip --no-exit-code", "knip": "knip --no-exit-code",
"lint": "node ./headers/lint.js && biome lint && node check-env-vars.js", "lint": "node ./headers/lint.js && biome lint",
"pg-typegen": "node ./headers/pg-typegen.js && npx kanel", "pg-typegen": "node ./headers/pg-typegen.js && npx kanel",
"start": "next start", "start": "next start",
"stripe-dev": "stripe listen --forward-to https://localhost:3000/api/stripe-webhook", "stripe-dev": "stripe listen --forward-to https://localhost:3000/api/stripe-webhook",

View file

@ -35,7 +35,6 @@
"node_modules", "node_modules",
"out", "out",
"dist", "dist",
"check-env-vars.js",
"headers", "headers",
"kyselyRules", "kyselyRules",
".kanelrc.js" ".kanelrc.js"