diff --git a/apps/server/.env.development b/apps/server/.env.development index 4b55c083..64ab9e10 100644 --- a/apps/server/.env.development +++ b/apps/server/.env.development @@ -22,4 +22,6 @@ JWT_ACCESS_EXPIRATION=1h JWT_REFRESH_EXPIRATION=7d -PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome \ No newline at end of file +PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome + +TEMPLATES_PATH=/home/rodax/Documentos/uecko-erp/modules \ No newline at end of file diff --git a/apps/server/.env.example b/apps/server/.env.example index 8c7cd088..fd4feeec 100644 --- a/apps/server/.env.example +++ b/apps/server/.env.example @@ -35,13 +35,6 @@ DB_SYNC_MODE=alter # none | alter | force -# ─────────────────────────────── -# Logging de la app -# ─────────────────────────────── -LOG_LEVEL=info # error | warn | info | debug -LOG_JSON=false # true para logs en JSON (entornos con agregadores) - - # ─────────────────────────────── # Warmup por módulo # ─────────────────────────────── @@ -61,4 +54,10 @@ JWT_REFRESH_EXPIRATION=7d # ─────────────────────────────── # Otros # ─────────────────────────────── -PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome \ No newline at end of file +PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome + + +# ─────────────────────────────── +# Plantillas +# ─────────────────────────────── +TEMPLATES_PATH=/opt/factuges/templates \ No newline at end of file diff --git a/apps/server/.env.production b/apps/server/.env.production index c8e86b5f..cec87282 100644 --- a/apps/server/.env.production +++ b/apps/server/.env.production @@ -34,4 +34,6 @@ JWT_SECRET=supersecretkey JWT_ACCESS_EXPIRATION=1h JWT_REFRESH_EXPIRATION=7d -PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome \ No newline at end of file +PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome + +TEMPLATES_PATH=/opt/factuges/templates \ No newline at end of file diff --git a/apps/server/src/config/index.ts b/apps/server/src/config/index.ts index 298eacd5..8e86fc00 100644 --- a/apps/server/src/config/index.ts +++ b/apps/server/src/config/index.ts @@ -40,6 +40,9 @@ const DB_SYNC_MODE = // Opcional: timezone para Sequelize (según necesidades) const APP_TIMEZONE = process.env.APP_TIMEZONE ?? "Europe/Madrid"; +// Ruta raíz para plantillas (templates) +const TEMPLATES_PATH = process.env.TEMPLATES_PATH ?? "./templates"; + // Proxy (no usáis ahora, pero dejamos la variable por si se activa en el futuro) const TRUST_PROXY = asNumber(process.env.TRUST_PROXY, 0); @@ -59,6 +62,7 @@ export const ENV = { DB_SYNC_MODE, APP_TIMEZONE, TRUST_PROXY, + TEMPLATES_PATH, } as const; export const Flags = { diff --git a/apps/server/src/index.ts b/apps/server/src/index.ts index f01a28af..82bbcd73 100644 --- a/apps/server/src/index.ts +++ b/apps/server/src/index.ts @@ -227,13 +227,21 @@ process.on("uncaughtException", async (error: Error) => { logger.info(`DB_LOGGING: ${ENV.DB_LOGGING}`); logger.info(`DB_SYNC_MODE: ${ENV.DB_SYNC_MODE}`); + logger.info(`TEMPLATES_PATH: ${ENV.TEMPLATES_PATH}`); + const database = await tryConnectToDatabase(); // Lógica de inicialización de DB, si procede: // initStructure(sequelizeConn.connection); // insertUsers(); - await initModules({ app, database, baseRoutePath: API_BASE_PATH, logger }); + await initModules({ + app, + database, + baseRoutePath: API_BASE_PATH, + logger, + templateRootPath: ENV.TEMPLATES_PATH, + }); // El servidor ya está listo para recibir tráfico isReady = true; diff --git a/apps/server/src/lib/modules/module-loader.ts b/apps/server/src/lib/modules/module-loader.ts index 0433612f..84f821b7 100644 --- a/apps/server/src/lib/modules/module-loader.ts +++ b/apps/server/src/lib/modules/module-loader.ts @@ -1,5 +1,7 @@ -import { IModuleServer, ModuleParams } from "@erp/core/api"; +import type { IModuleServer, ModuleParams } from "@erp/core/api"; + import { logger } from "../logger"; + import { initModels, registerModels } from "./model-loader"; import { getService, listServices, registerService } from "./service-registry"; diff --git a/apps/server/src/register-modules.ts b/apps/server/src/register-modules.ts index 934dd0ed..a20cc3b5 100644 --- a/apps/server/src/register-modules.ts +++ b/apps/server/src/register-modules.ts @@ -1,5 +1,6 @@ import customerInvoicesAPIModule from "@erp/customer-invoices/api"; import customersAPIModule from "@erp/customers/api"; + //import verifactuAPIModule from "@erp/verifactu/api"; import { registerModule } from "./lib"; diff --git a/package.json b/package.json index 717446db..5fcda381 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,8 @@ ], "scripts": { "build": "turbo build", + "build:templates": "bash scripts/build-templates.sh", + "build:api": "bash scripts/build-api.sh rodax --api", "dev": "turbo dev", "dev:server": "turbo dev --filter=server", "dev:client": "turbo dev --filter=client", diff --git a/scripts/build-templates.sh b/scripts/build-templates.sh new file mode 100755 index 00000000..b7cd07ee --- /dev/null +++ b/scripts/build-templates.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +# Fail fast +set -euo pipefail + +# Root directory (dir where the script lives, then go up) +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +SOURCE_DIR="$ROOT_DIR/modules" +TARGET_DIR="$ROOT_DIR/apps/server/dist/templates" + +echo "[build-templates] Root: $ROOT_DIR" +echo "[build-templates] Source: $SOURCE_DIR" +echo "[build-templates] Target: $TARGET_DIR" + +# Ensure target directory exists and is empty +rm -rf "$TARGET_DIR" +mkdir -p "$TARGET_DIR" + +# Loop through each package +for module in "$SOURCE_DIR"/*; do + if [ -d "$module/templates" ]; then + module_name=$(basename "$module") + echo "→ Copying templates for module: $module_name" + + mkdir -p "$TARGET_DIR/$module_name" + cp -R "$module/templates/." "$TARGET_DIR/$module_name/" + fi +done + +echo "[build-templates] Completed." diff --git a/turbo.json b/turbo.json index ffc77dcf..dec22a3b 100644 --- a/turbo.json +++ b/turbo.json @@ -17,6 +17,10 @@ "inputs": ["$TURBO_DEFAULT$", ".env*"], "outputs": ["dist/**"] }, + "build:templates": { + "dependsOn": [], + "outputs": ["dist/templates/**"] + }, "clean": { "cache": false }