#!/bin/bash # mcmqtt Documentation Site Build Script # Professional Astro/Starlight documentation builder set -e echo "🚀 Building mcmqtt documentation site..." # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' BLUE='\033[0;34m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Check if Node.js is installed if ! command -v node &> /dev/null; then echo -e "${RED}❌ Node.js is not installed. Please install Node.js 18+ to continue.${NC}" exit 1 fi # Check Node.js version NODE_VERSION=$(node -v | sed 's/v//') REQUIRED_VERSION="18.0.0" if [ "$(printf '%s\n' "$REQUIRED_VERSION" "$NODE_VERSION" | sort -V | head -n1)" != "$REQUIRED_VERSION" ]; then echo -e "${RED}❌ Node.js version $NODE_VERSION is too old. Please install Node.js 18+ to continue.${NC}" exit 1 fi echo -e "${GREEN}✅ Node.js version $NODE_VERSION detected${NC}" # Install dependencies echo -e "${BLUE}📦 Installing dependencies...${NC}" if command -v npm &> /dev/null; then npm install else echo -e "${RED}❌ npm is not available. Please ensure Node.js is properly installed.${NC}" exit 1 fi # Run Astro check echo -e "${BLUE}🔍 Running Astro type checking...${NC}" npm run astro check # Build the site echo -e "${BLUE}🔨 Building documentation site...${NC}" npm run build # Check if build was successful if [ $? -eq 0 ]; then echo -e "${GREEN}✅ Documentation site built successfully!${NC}" echo -e "${YELLOW}📁 Built files are in the 'dist' directory${NC}" echo -e "${YELLOW}🌐 You can serve the site locally with: npm run preview${NC}" else echo -e "${RED}❌ Build failed. Please check the error messages above.${NC}" exit 1 fi # Display build statistics if [ -d "dist" ]; then TOTAL_SIZE=$(du -sh dist | cut -f1) FILE_COUNT=$(find dist -type f | wc -l) echo -e "${GREEN}📊 Build Statistics:${NC}" echo -e " Total size: $TOTAL_SIZE" echo -e " File count: $FILE_COUNT" # Check for large files echo -e "${BLUE}🔍 Checking for large files...${NC}" find dist -type f -size +1M -exec ls -lh {} \; | awk '{print $5 " " $9}' | while read size file; do echo -e "${YELLOW} Large file: $file ($size)${NC}" done fi echo -e "${GREEN}🎉 mcmqtt documentation site is ready to deploy!${NC}" # Deployment suggestions echo -e "${BLUE}🚀 Deployment Options:${NC}" echo -e " • Vercel: vercel --prod" echo -e " • Netlify: netlify deploy --prod --dir=dist" echo -e " • GitHub Pages: Push to gh-pages branch" echo -e " • Any static host: Upload dist/ directory"