| #!/bin/bash |
| |
| set -e |
|
|
| cd "$(dirname "$0")/.." |
|
|
| BUN_MIN_VERSION="1.2.0" |
|
|
| confirm() { |
| if [ ! -t 0 ]; then |
| return 1 |
| fi |
|
|
| echo -n "$1 [y/N] " |
| read -r answer |
| [[ "$answer" =~ ^[Yy]$ ]] |
| } |
|
|
| version_ge() { |
| local current="${1#v}" |
| local minimum="${2#v}" |
| local current_major current_minor current_patch |
| local minimum_major minimum_minor minimum_patch |
|
|
| IFS='.' read -r current_major current_minor current_patch <<< "${current}" |
| IFS='.' read -r minimum_major minimum_minor minimum_patch <<< "${minimum}" |
|
|
| current_minor=${current_minor:-0} |
| current_patch=${current_patch:-0} |
| minimum_minor=${minimum_minor:-0} |
| minimum_patch=${minimum_patch:-0} |
|
|
| if [ "$current_major" -ne "$minimum_major" ]; then |
| [ "$current_major" -gt "$minimum_major" ] |
| return |
| fi |
|
|
| if [ "$current_minor" -ne "$minimum_minor" ]; then |
| [ "$current_minor" -gt "$minimum_minor" ] |
| return |
| fi |
|
|
| [ "$current_patch" -ge "$minimum_patch" ] |
| } |
|
|
| if ! command -v bun &> /dev/null; then |
| echo "β ERROR: Bun is required to build the dashboard" |
| echo " Install it with: curl -fsSL https://bun.sh/install | bash" |
| exit 1 |
| fi |
|
|
| BUN_VERSION="$(bun -v)" |
| if ! version_ge "$BUN_VERSION" "$BUN_MIN_VERSION"; then |
| echo "β ERROR: Bun $BUN_VERSION is too old for dashboard/bun.lock" |
| echo " Clean installs require Bun $BUN_MIN_VERSION+" |
| echo " Upgrade with: curl -fsSL https://bun.sh/install | bash" |
| exit 1 |
| fi |
|
|
| echo "π¦ Building React dashboard..." |
| cd dashboard |
|
|
| |
| echo "π₯ Syncing dashboard dependencies..." |
| bun install --frozen-lockfile |
|
|
| |
| TYGO="${GOPATH:-$HOME/go}/bin/tygo" |
| if [ -x "$TYGO" ]; then |
| echo "π Generating TypeScript types..." |
| "$TYGO" generate |
| elif command -v tygo &> /dev/null; then |
| echo "π Generating TypeScript types..." |
| tygo generate |
| else |
| if command -v go &> /dev/null && confirm "Install tygo via go install?"; then |
| go install github.com/gzuidhof/tygo@latest |
| TYGO="${GOPATH:-$HOME/go}/bin/tygo" |
| if [ -x "$TYGO" ]; then |
| echo "π Generating TypeScript types..." |
| "$TYGO" generate |
| elif command -v tygo &> /dev/null; then |
| echo "π Generating TypeScript types..." |
| tygo generate |
| else |
| echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ" |
| echo "β οΈ WARNING: tygo install completed but binary was not found on PATH" |
| echo " Restart your shell or ensure \$GOPATH/bin is on PATH." |
| echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ" |
| fi |
| else |
| echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ" |
| echo "β οΈ WARNING: tygo not found β skipping TypeScript type generation" |
| echo " Types in the dashboard might fall out of sync with Go structs." |
| echo " Install it with: go install github.com/gzuidhof/tygo@latest" |
| echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ" |
| fi |
| fi |
|
|
| |
| if [ -f "src/generated/types.ts" ]; then |
| npx prettier --write src/generated/types.ts 2>/dev/null || true |
| fi |
|
|
| bun run build |
|
|
| echo "π Copying build to internal/dashboard/dashboard/..." |
| cd .. |
|
|
| |
| rm -rf internal/dashboard/dashboard/assets/ |
| rm -f internal/dashboard/dashboard/dashboard.html |
|
|
| |
| |
| |
| cp -r dashboard/dist/* internal/dashboard/dashboard/ |
| mv internal/dashboard/dashboard/index.html internal/dashboard/dashboard/dashboard.html |
|
|
| echo "β
Dashboard built: internal/dashboard/dashboard/" |
|
|