Compare commits

...

2 Commits

2 changed files with 23 additions and 6 deletions
+4
View File
@@ -53,6 +53,10 @@
{
"from": "static",
"to": "static"
},
{
"from": ".env",
"to": ".env"
}
],
"mac": {
+19 -6
View File
@@ -1,4 +1,5 @@
import fs from "node:fs";
import path from "node:path";
export type AppRuntimeConfig = {
title: string;
@@ -23,13 +24,9 @@ const MIN_TCP_PORT = 1;
const MAX_TCP_PORT = 65535;
export function loadEnvFile(envFilePath: string): void {
if (!fs.existsSync(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.`,
);
}
const resolvedPath = resolveEnvFilePath(envFilePath);
try {
process.loadEnvFile(envFilePath);
process.loadEnvFile(resolvedPath);
} catch (error) {
throw new 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 {
return {
title: getRequiredEnv("SCOREKO_APP_TITLE"),