Files
firefrost-services/services/modpack-version-checker/blueprint-extension/build.sh
Claude (Chronicler #83 - The Compiler) 28608e9fa8 Build pipeline hardening: ErrorBoundary, no PHP copies, TS pre-flight
- ErrorBoundary.tsx wraps widget — crashes show fallback, not blank void
- build.sh v1.1.0: removed ALL PHP file copies (Chronicler deploys manually)
- Added set -e / set -u for fail-fast
- Added TypeScript pre-flight check (yarn tsc --noEmit) before build
- Added dynamic Blueprint controller detection via find
- Widget injection now wrapped in <ModpackErrorBoundary>
- Pre-commit PHP lint hook at scripts/pre-commit-hook.sh

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 00:17:30 -05:00

163 lines
6.1 KiB
Bash
Executable File

#!/bin/bash
# =============================================================================
# MODPACK VERSION CHECKER - BUILD SCRIPT
# =============================================================================
#
# Handles TSX injection + frontend compilation ONLY.
# PHP files are deployed manually by Chronicler from the repo.
#
# @author Firefrost Gaming / Frostystyle <dev@firefrostgaming.com>
# @version 1.1.0
# =============================================================================
set -e
set -u
echo "=========================================="
echo "ModpackChecker Build Script v1.1.0"
echo "=========================================="
# Determine the extension source directory
if [ -d ".blueprint/extensions/modpackchecker/views" ]; then
EXT_DIR=".blueprint/extensions/modpackchecker"
elif [ -d ".blueprint/dev/views" ]; then
EXT_DIR=".blueprint/dev"
else
echo "ERROR: Cannot find extension views directory"
exit 1
fi
echo "Using extension directory: $EXT_DIR"
# ===========================================
# 0. NODE VERSION DETECTION
# ===========================================
NODE_MAJOR_VERSION=$(node -v | grep -oE '[0-9]+' | head -1)
echo "Detected Node.js version: v$NODE_MAJOR_VERSION"
if [ "$NODE_MAJOR_VERSION" -lt 16 ]; then
echo "ERROR: ModpackChecker requires Node.js 16 or higher."
exit 1
fi
if [ "$NODE_MAJOR_VERSION" -ge 17 ]; then
echo "Applying OpenSSL legacy provider for Node 17+ compatibility..."
export NODE_OPTIONS=--openssl-legacy-provider
fi
# ===========================================
# 1. CONSOLE WIDGET + ERROR BOUNDARY
# ===========================================
echo ""
echo "--- Console Widget ---"
if [ -f "$EXT_DIR/views/server/wrapper.tsx" ]; then
cp "$EXT_DIR/views/server/wrapper.tsx" resources/scripts/components/server/ModpackVersionCard.tsx
echo "✓ Copied ModpackVersionCard.tsx"
else
echo "⚠ wrapper.tsx not found, skipping console widget"
fi
if [ -f "$EXT_DIR/views/server/ErrorBoundary.tsx" ]; then
cp "$EXT_DIR/views/server/ErrorBoundary.tsx" resources/scripts/components/server/ModpackErrorBoundary.tsx
echo "✓ Copied ModpackErrorBoundary.tsx"
else
echo "⚠ ErrorBoundary.tsx not found, skipping error boundary"
fi
# Inject into AfterInformation.tsx (wrapped in ErrorBoundary)
AFTER_INFO="resources/scripts/blueprint/components/Server/Terminal/AfterInformation.tsx"
if [ -f "$AFTER_INFO" ]; then
if ! grep -q "ModpackVersionCard" "$AFTER_INFO" 2>/dev/null; then
sed -i '/\/\* blueprint\/import \*\//a import ModpackVersionCard from "@/components/server/ModpackVersionCard";\nimport ModpackErrorBoundary from "@/components/server/ModpackErrorBoundary";' "$AFTER_INFO"
sed -i 's|{/\* blueprint/react \*/}|{/* blueprint/react */}\n <ModpackErrorBoundary><ModpackVersionCard /></ModpackErrorBoundary>|' "$AFTER_INFO"
echo "✓ Injected ModpackVersionCard (with ErrorBoundary) into AfterInformation.tsx"
else
echo "○ ModpackVersionCard already present in AfterInformation.tsx"
fi
else
echo "⚠ AfterInformation.tsx not found, skipping injection"
fi
# ===========================================
# 2. DASHBOARD BADGE INJECTION
# ===========================================
echo ""
echo "--- Dashboard Badge ---"
if [ -f "$EXT_DIR/views/dashboard/UpdateBadge.tsx" ]; then
mkdir -p resources/scripts/components/dashboard
cp "$EXT_DIR/views/dashboard/UpdateBadge.tsx" resources/scripts/components/dashboard/UpdateBadge.tsx
echo "✓ Copied UpdateBadge.tsx"
else
echo "⚠ UpdateBadge.tsx not found, skipping dashboard badge"
fi
if ! grep -q "UpdateBadge" resources/scripts/components/dashboard/ServerRow.tsx 2>/dev/null; then
sed -i '1i import UpdateBadge from "@/components/dashboard/UpdateBadge";' resources/scripts/components/dashboard/ServerRow.tsx
sed -i 's|{server.name}</p>|{server.name}<UpdateBadge serverUuid={server.uuid} /></p>|' resources/scripts/components/dashboard/ServerRow.tsx
echo "✓ Injected UpdateBadge into ServerRow.tsx"
else
echo "○ UpdateBadge already present in ServerRow.tsx"
fi
# ===========================================
# 3. ADMIN CONTROLLER (Blueprint auto-generated)
# ===========================================
echo ""
echo "--- Admin Controller ---"
BP_CONTROLLER=$(find app/Http/Controllers/Admin/Extensions/modpackchecker -name "*Controller.php" 2>/dev/null | head -n 1)
if [ -n "$BP_CONTROLLER" ]; then
cp "$EXT_DIR/admin/controller.php" "$BP_CONTROLLER"
echo "✓ Overwrote Blueprint controller: $BP_CONTROLLER"
else
echo "⚠ Blueprint controller not found — admin panel may need manual controller deploy"
fi
# ===========================================
# 4. CLEAR CACHES
# ===========================================
echo ""
echo "--- Cache Clear ---"
php artisan optimize:clear 2>/dev/null && echo "✓ Laravel caches cleared" || echo "⚠ Cache clear skipped (non-fatal)"
# ===========================================
# 5. TYPESCRIPT PRE-FLIGHT CHECK
# ===========================================
echo ""
echo "--- TypeScript Check ---"
if command -v yarn &>/dev/null; then
yarn tsc --noEmit 2>&1 | head -20 || {
echo "❌ TypeScript validation failed — aborting build"
exit 1
}
echo "✓ TypeScript check passed"
fi
# ===========================================
# 6. COMPILE FRONTEND ASSETS
# ===========================================
echo ""
echo "--- Frontend Build ---"
if command -v yarn &>/dev/null; then
echo "Running yarn build:production (this may take 2-5 minutes)..."
yarn build:production 2>&1 && echo "✓ Frontend assets compiled" || {
echo "⚠ Frontend build failed — dashboard badges and widget will not render"
echo " Admin panel + cron + license system still work fine"
}
else
echo "⚠ yarn not found — skipping frontend build"
fi
echo ""
echo "=========================================="
echo "ModpackChecker build complete!"
echo "=========================================="
echo ""
echo "Next steps:"
echo " 1. Deploy PHP files from repo (Chronicler)"
echo " 2. Restart: systemctl restart php8.3-fpm"
echo " 3. Test cron: php artisan modpackchecker:check"
echo ""