refactor: remove check-env-vars.js and update lint script to streamline environment checks
This commit is contained in:
parent
8a17863c85
commit
f904500e2d
4 changed files with 4 additions and 55 deletions
|
|
@ -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}`);
|
||||
}
|
||||
|
|
@ -8,6 +8,6 @@ console.log(
|
|||
| |____| | | | | |_
|
||||
\\_____/|_|_| |_|\\__|
|
||||
|
||||
🔍 Linting and Env Checks...
|
||||
🔍 Linting ...
|
||||
`,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
"email": "cross-env NEXT_PUBLIC_BASE_URL='https://localhost:3000' email dev --port 3500",
|
||||
"idev": "cross-env NODE_OPTIONS='--inspect' next dev --turbopack",
|
||||
"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",
|
||||
"start": "next start",
|
||||
"stripe-dev": "stripe listen --forward-to https://localhost:3000/api/stripe-webhook",
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@
|
|||
"node_modules",
|
||||
"out",
|
||||
"dist",
|
||||
"check-env-vars.js",
|
||||
"headers",
|
||||
"kyselyRules",
|
||||
".kanelrc.js"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue