Files
tasks/scripts/sync-admin-ui.sh

55 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# sync-admin-ui.sh — sync the admin-tasks @hanzo/gui v7 bundle into ui/dist.
#
# The Tasks SPA is built externally in the @hanzo/gui workspace at
# ~/work/hanzo/gui/apps/admin-tasks (Vite + @hanzo/gui v7). This script
# copies the built bundle into ui/dist/ where //go:embed picks it up
# at compile time of cmd/tasksd. Reproducible, idempotent, CI-friendly.
#
# Usage:
# scripts/sync-admin-ui.sh # uses ../gui/apps/admin-tasks
# ADMIN_TASKS_DIR=/path scripts/sync-admin-ui.sh
#
# Exits non-zero if the source dist/ is missing or empty so CI fails
# loud instead of shipping a binary with a stale or empty SPA.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
DEFAULT_SRC="$(cd "${REPO_ROOT}/../gui/apps/admin-tasks" 2>/dev/null && pwd || echo "")"
SRC="${ADMIN_TASKS_DIR:-${DEFAULT_SRC}}"
DST="${REPO_ROOT}/ui/dist"
if [[ -z "${SRC}" || ! -d "${SRC}/dist" ]]; then
echo "error: admin-tasks dist not found." >&2
echo " expected: ${SRC:-<unset>}/dist" >&2
echo " build it first: cd \"${SRC:-../gui/apps/admin-tasks}\" && bun run build" >&2
echo " or set ADMIN_TASKS_DIR=/abs/path/to/admin-tasks" >&2
exit 1
fi
if ! ls "${SRC}/dist"/index.html "${SRC}/dist"/assets/*.js >/dev/null 2>&1; then
echo "error: ${SRC}/dist is missing index.html or assets/*.js" >&2
exit 1
fi
mkdir -p "${DST}"
rsync -a --delete "${SRC}/dist/" "${DST}/"
# Stamp the sync so binaries can be traced back to a build.
{
echo "# auto-generated by scripts/sync-admin-ui.sh — do not edit"
echo "source=${SRC}"
echo "synced_at=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
if command -v git >/dev/null 2>&1 && git -C "${SRC}" rev-parse --short HEAD >/dev/null 2>&1; then
echo "source_commit=$(git -C "${SRC}" rev-parse --short HEAD)"
fi
if command -v git >/dev/null 2>&1 && git -C "${SRC}" status --porcelain >/dev/null 2>&1; then
if [[ -n "$(git -C "${SRC}" status --porcelain || true)" ]]; then
echo "source_dirty=true"
fi
fi
} > "${DST}/.sync-stamp"
echo "synced ${SRC}/dist -> ${DST}"
ls -lh "${DST}/index.html" "${DST}"/assets/*.js "${DST}"/assets/*.css 2>/dev/null