Extraction des secrets
This commit is contained in:
33
tools/lib/env.js
Normal file
33
tools/lib/env.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
let envLoaded = false;
|
||||
|
||||
function loadEnv(envPath = path.resolve(__dirname, "..", "..", ".env")) {
|
||||
if (envLoaded) return;
|
||||
envLoaded = true;
|
||||
|
||||
if (!fs.existsSync(envPath)) return;
|
||||
|
||||
const content = fs.readFileSync(envPath, "utf8");
|
||||
const lines = content.split(/\r?\n/);
|
||||
|
||||
for (const line of lines) {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed || trimmed.startsWith("#")) continue;
|
||||
|
||||
const separator = trimmed.indexOf("=");
|
||||
if (separator === -1) continue;
|
||||
|
||||
const key = trimmed.slice(0, separator).trim();
|
||||
const value = trimmed.slice(separator + 1);
|
||||
|
||||
if (!key || process.env[key] !== undefined) continue;
|
||||
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
loadEnv,
|
||||
};
|
||||
Reference in New Issue
Block a user