Compare commits

...

2 Commits

2 changed files with 23 additions and 6 deletions
+4
View File
@@ -53,6 +53,10 @@
{ {
"from": "static", "from": "static",
"to": "static" "to": "static"
},
{
"from": ".env",
"to": ".env"
} }
], ],
"mac": { "mac": {
+19 -6
View File
@@ -1,4 +1,5 @@
import fs from "node:fs"; import fs from "node:fs";
import path from "node:path";
export type AppRuntimeConfig = { export type AppRuntimeConfig = {
title: string; title: string;
@@ -23,13 +24,9 @@ const MIN_TCP_PORT = 1;
const MAX_TCP_PORT = 65535; const MAX_TCP_PORT = 65535;
export function loadEnvFile(envFilePath: string): void { export function loadEnvFile(envFilePath: string): void {
if (!fs.existsSync(envFilePath)) { const resolvedPath = resolveEnvFilePath(envFilePath);
throw new Error(
`Archivo de configuración obligatorio no encontrado: ${envFilePath}\n\nPor favor, crea un archivo .env basado en .env.example en la raíz de la aplicación.`,
);
}
try { try {
process.loadEnvFile(envFilePath); process.loadEnvFile(resolvedPath);
} catch (error) { } catch (error) {
throw new Error( throw new Error(
`Error al leer el archivo de configuración .env: ${error instanceof Error ? error.message : String(error)}`, `Error al leer el archivo de configuración .env: ${error instanceof Error ? error.message : String(error)}`,
@@ -37,6 +34,22 @@ export function loadEnvFile(envFilePath: string): void {
} }
} }
function resolveEnvFilePath(envFilePath: string): string {
if (fs.existsSync(envFilePath)) {
return envFilePath;
}
const dir = path.dirname(envFilePath);
const fallbackPath = path.join(dir, ".env.example");
if (fs.existsSync(fallbackPath)) {
return fallbackPath;
}
throw new Error(
`Archivo de configuración obligatorio no encontrado: ${envFilePath}\n\nPor favor, crea un archivo .env basado en .env.example en la raíz de la aplicación.`,
);
}
export function getRuntimeConfig(): AppRuntimeConfig { export function getRuntimeConfig(): AppRuntimeConfig {
return { return {
title: getRequiredEnv("SCOREKO_APP_TITLE"), title: getRequiredEnv("SCOREKO_APP_TITLE"),