Files
zeekay 1943f1c093 Hanzo Commerce
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans,
usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0.

Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
2026-09-23 21:52:16 -07:00

54 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# sync-admin-ui.sh — sync THE Commerce admin export into ui/dist.
#
# There is one Commerce admin: app/admin (@hanzo/commerce-dashboard, Next.js
# `output: export`, built on @hanzo/ui + @hanzo/gui). Build it first
# (`cd app && pnpm turbo run typecheck build --filter=@hanzo/commerce-dashboard`)
# and this copies app/admin/out into ui/dist/ where //go:embed picks it up at
# compile time of cmd/commerced. Reproducible, idempotent, CI-friendly.
#
# Usage:
# scripts/sync-admin-ui.sh # uses app/admin/out
# ADMIN_COMMERCE_DIR=/path scripts/sync-admin-ui.sh # dir containing out/
#
# Exits non-zero if the export 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)"
SRC="${ADMIN_COMMERCE_DIR:-${REPO_ROOT}/app/admin}"
DST="${REPO_ROOT}/ui/dist"
if [[ ! -d "${SRC}/out" ]]; then
echo "error: admin export not found." >&2
echo " expected: ${SRC}/out" >&2
echo " build it first: cd app && pnpm turbo run typecheck build --filter=@hanzo/commerce-dashboard" >&2
exit 1
fi
if ! ls "${SRC}/out"/index.html >/dev/null 2>&1; then
echo "error: ${SRC}/out is missing index.html" >&2
exit 1
fi
mkdir -p "${DST}"
rsync -a --delete --exclude=.gitkeep "${SRC}/out/" "${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}/out -> ${DST}"
ls -lh "${DST}/index.html" 2>/dev/null