#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
IMAGE_NAME="cadroute-builder-windows"

echo "[cadroute] Building Docker image..."
docker build -t "$IMAGE_NAME" "$SCRIPT_DIR"

echo "[cadroute] Running Windows build..."
docker run --rm \
  -v "$PROJECT_ROOT":/project \
  -w /project \
  -v cadroute-electron-cache:/root/.cache/electron \
  -v cadroute-electronbuilder-cache:/root/.cache/electron-builder \
  "$IMAGE_NAME" \
  bash -c "npm ci && npm run build -- --win --x64"

echo "[cadroute] Artefatti in: $PROJECT_ROOT/dist"
