#!/usr/bin/env bash
# EUcoder X — macOS Apple Silicon: CLI + IDE desktop (beta build da sorgente)
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
bash "${SCRIPT_DIR}/eucoder-x-cli.sh"

if command -v cargo >/dev/null 2>&1; then
  INSTALL_DIR="${CODERX_INSTALL_DIR:-$HOME/.local/share/eucoder-x}"
  echo ""
  echo "Rust trovato — build IDE desktop (può richiedere diversi minuti)…"
  cd "${INSTALL_DIR}/apps/desktop"
  npm install --no-audit --no-fund
  npm run tauri:build
  echo "Build completata. Cerca .dmg in apps/desktop/src-tauri/target/release/bundle/"
else
  echo ""
  echo "Installer .dmg ufficiale in arrivo su https://eucoder.com/install"
  echo "Beta: installa Rust (rustup.rs), poi riesegui questo script."
  echo "Oppure: cd ~/.local/share/eucoder-x/apps/desktop && npm run tauri:build"
fi
