#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
SRC_DIR="$ROOT/extension/gluecron.dxt"
OUT_DIR="$ROOT/public"
OUT_FILE="$OUT_DIR/gluecron.dxt"
say() { printf "\n\033[1;34m> %s\033[0m\n" "$*"; }
ok() { printf " \033[32mv\033[0m %s\n" "$*"; }
warn() { printf " \033[33m!\033[0m %s\n" "$*"; }
fail() { printf " \033[31mx\033[0m %s\n" "$*"; exit 1; }
say "[1/4] Checking prerequisites"
command -v zip >/dev/null 2>&1 || fail "zip is not on PATH — install it (apt: zip / brew: zip) and retry"
ok "zip found: $(command -v zip)"
[[ -d "$SRC_DIR" ]] || fail "extension/gluecron.dxt/ missing — bad checkout?"
[[ -f "$SRC_DIR/manifest.json" ]] || fail "manifest.json missing under $SRC_DIR"
ok "source tree at $SRC_DIR"
say "[2/4] Validating manifest.json"
if command -v bun >/dev/null 2>&1; then
bun -e "JSON.parse(require('fs').readFileSync('$SRC_DIR/manifest.json','utf8'))" \
|| fail "manifest.json is not valid JSON"
elif command -v node >/dev/null 2>&1; then
node -e "JSON.parse(require('fs').readFileSync('$SRC_DIR/manifest.json','utf8'))" \
|| fail "manifest.json is not valid JSON"
elif command -v python3 >/dev/null 2>&1; then
python3 -c "import json,sys;json.load(open('$SRC_DIR/manifest.json'))" \
|| fail "manifest.json is not valid JSON"
else
warn "no bun/node/python3 — skipping JSON validation"
fi
ok "manifest.json is valid"
say "[3/4] Refreshing placeholder assets"
if command -v bun >/dev/null 2>&1 && [[ -f "$ROOT/scripts/build-dxt-assets.ts" ]]; then
bun run "$ROOT/scripts/build-dxt-assets.ts"
ok "assets refreshed"
else
warn "bun missing or build-dxt-assets.ts not found — using committed PNGs as-is"
fi
say "[4/4] Packaging gluecron.dxt"
mkdir -p "$OUT_DIR"
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT
cp -R "$SRC_DIR/." "$TMP_DIR/"
rm -f "$OUT_FILE"
( cd "$TMP_DIR" && zip -q -r "$OUT_FILE" . )
ok "wrote $OUT_FILE"
SIZE=$(wc -c < "$OUT_FILE" | tr -d ' ')
HUMAN=$(printf "%.1f KB" "$(echo "scale=1; $SIZE/1024" | bc 2>/dev/null || echo "$SIZE")" 2>/dev/null || echo "$SIZE bytes")
ok "size: $HUMAN ($SIZE bytes)"
printf "\nDone. Test locally:\n curl -I http://localhost:3000/gluecron.dxt\n\n"
|