#!/usr/bin/env bash
# Construit build/gcms-${VERSION}.zip (allowlist identique à GcmsUpdateService).
# Usage : VERSION=1.2.3 bash scripts/build-gcms-release.sh
set -euo pipefail

ROOT="$(cd "$(dirname "$0")/.." && pwd)"
VERSION="${VERSION:-}"
if [[ -z "$VERSION" ]]; then
  echo "Erreur : définir VERSION (ex. VERSION=1.2.3)" >&2
  exit 1
fi

OUT="${ROOT}/build"
mkdir -p "${OUT}"
ZIP="${OUT}/gcms-${VERSION}.zip"
cd "${ROOT}"
rm -f "${ZIP}"

zip -rq "${ZIP}" \
  app \
  artisan \
  bootstrap \
  composer.json \
  composer.lock \
  config \
  database \
  plugins \
  public \
  resources \
  routes \
  themes/classic \
  -x "public/storage/*" \
  -x "config/installed.lock" \
  -x "*.git/*" \
  -x "*node_modules/*" \
  -x "*.md"

echo "OK : ${ZIP}"
