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

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
OUT_DIR="${ROOT_DIR}/release"
STAMP="$(date +%Y%m%d-%H%M%S)"
PKG_NAME="davos-assessment-server-${STAMP}.tar.gz"

mkdir -p "${OUT_DIR}"

cd "${ROOT_DIR}"
tar \
  --exclude='.git' \
  --exclude='.DS_Store' \
  --exclude='*/.DS_Store' \
  --exclude='.env.local' \
  --exclude='frontend/.env.local' \
  --exclude='frontend/node_modules' \
  --exclude='backend/node_modules' \
  --exclude='frontend/dist' \
  --exclude='backend/target' \
  --exclude='release' \
  --exclude='*.tar.gz' \
  --exclude='*.zip' \
  --exclude='*.log' \
  -czf "${OUT_DIR}/${PKG_NAME}" \
  .

echo "PACKAGE=${OUT_DIR}/${PKG_NAME}"
