mirror of
https://github.com/Pandipipas/scoreko-electron-dev.git
synced 2026-06-06 05:32:06 +00:00
env config
This commit is contained in:
+33
-8
@@ -7,12 +7,31 @@ import { bundleName, nodecgRuntimeRoot } from "./build-config.mjs";
|
||||
|
||||
const checks = [];
|
||||
|
||||
function loadEnv() {
|
||||
if (!fs.existsSync(".env")) {
|
||||
console.error("FAIL Configuración: Archivo .env obligatorio no encontrado.");
|
||||
console.error("Por favor, crea un archivo .env basado en .env.example en la raíz del proyecto.");
|
||||
process.exit(1);
|
||||
}
|
||||
try {
|
||||
process.loadEnvFile(".env");
|
||||
console.log("OK Configuración: Archivo .env cargado correctamente.\n");
|
||||
} catch (error) {
|
||||
console.error(`FAIL Configuración: Error al leer el archivo .env: ${error.message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
function addCheck(ok, title, details) {
|
||||
checks.push({ ok, title, details });
|
||||
}
|
||||
|
||||
function parsePort(name, fallback) {
|
||||
const raw = process.env[name] ?? fallback;
|
||||
function parsePort(name) {
|
||||
const raw = process.env[name];
|
||||
if (!raw) {
|
||||
addCheck(false, `${name} missing`, `The required environment variable ${name} is not defined in the .env file.`);
|
||||
return null;
|
||||
}
|
||||
const parsed = Number.parseInt(raw, 10);
|
||||
if (!Number.isFinite(parsed) || parsed < 1 || parsed > 65535) {
|
||||
addCheck(false, `${name} invalid`, `It must be an integer between 1 and 65535. Received value: '${raw}'.`);
|
||||
@@ -23,8 +42,12 @@ function parsePort(name, fallback) {
|
||||
return parsed;
|
||||
}
|
||||
|
||||
function parseIntInRange(name, fallback, min, max) {
|
||||
const raw = process.env[name] ?? String(fallback);
|
||||
function parseIntInRange(name, min, max) {
|
||||
const raw = process.env[name];
|
||||
if (!raw) {
|
||||
addCheck(false, `${name} missing`, `The required environment variable ${name} is not defined in the .env file.`);
|
||||
return;
|
||||
}
|
||||
const parsed = Number.parseInt(raw, 10);
|
||||
if (!Number.isFinite(parsed) || parsed < min || parsed > max) {
|
||||
addCheck(false, `${name} invalid`, `It must be an integer between ${min} and ${max}. Received value: '${raw}'.`);
|
||||
@@ -73,10 +96,12 @@ function checkPortAvailability(port) {
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const port = parsePort("NODECG_PORT", "9090");
|
||||
parseIntInRange("ELECTRON_LOAD_DELAY_MS", 10000, 0, 600000);
|
||||
parseIntInRange("NODECG_STARTUP_TIMEOUT_MS", 120000, 1000, 600000);
|
||||
parseIntInRange("NODECG_KILL_TIMEOUT_MS", 2500, 0, 120000);
|
||||
loadEnv();
|
||||
|
||||
const port = parsePort("NODECG_PORT");
|
||||
parseIntInRange("ELECTRON_LOAD_DELAY_MS", 0, 600000);
|
||||
parseIntInRange("NODECG_STARTUP_TIMEOUT_MS", 1000, 600000);
|
||||
parseIntInRange("NODECG_KILL_TIMEOUT_MS", 0, 120000);
|
||||
checkNodecgInstall();
|
||||
|
||||
if (port) {
|
||||
|
||||
Reference in New Issue
Block a user