#!/bin/bash # Trigo Hugging Face Space Deployment Script # This script copies the trigo-web project to the HF Space repo and prepares it for deployment set -e echo "๐Ÿš€ Trigo HF Space Deployment Script" echo "====================================" echo "" # Define paths PROJECT_ROOT="/home/camus/work/trigo" TRIGO_WEB="$PROJECT_ROOT/trigo-web" HF_SPACE="$PROJECT_ROOT/third_party/trigo-hfspace" # Check if directories exist if [ ! -d "$TRIGO_WEB" ]; then echo "โŒ Error: trigo-web directory not found at $TRIGO_WEB" exit 1 fi if [ ! -d "$HF_SPACE" ]; then echo "โŒ Error: HF Space directory not found at $HF_SPACE" exit 1 fi echo "๐Ÿ“‚ Project directory: $TRIGO_WEB" echo "๐Ÿ“‚ HF Space directory: $HF_SPACE" echo "" # Clean up old trigo-web in HF space if it exists if [ -d "$HF_SPACE/trigo-web" ]; then echo "๐Ÿงน Cleaning up old trigo-web directory..." rm -rf "$HF_SPACE/trigo-web" fi # Copy trigo-web to HF space echo "๐Ÿ“ฆ Copying trigo-web to HF Space repository..." cp -r "$TRIGO_WEB" "$HF_SPACE/" # Remove node_modules and dist folders (will be built in Docker) echo "๐Ÿงน Removing node_modules and dist folders (will be rebuilt in Docker)..." find "$HF_SPACE/trigo-web" -type d -name "node_modules" -exec rm -rf {} + 2>/dev/null || true find "$HF_SPACE/trigo-web" -type d -name "dist" -exec rm -rf {} + 2>/dev/null || true # Remove test files echo "๐Ÿงน Removing test files..." rm -rf "$HF_SPACE/trigo-web/tests" 2>/dev/null || true # Apply HF Space specific patches echo "๐Ÿ”ง Applying HF Space patches..." # Create tsconfig.json for app echo " Creating tsconfig.json..." cat > "$HF_SPACE/trigo-web/app/tsconfig.json" << 'EOF' { "compilerOptions": { "target": "ES2020", "useDefineForClassFields": true, "module": "ESNext", "lib": ["ES2020", "DOM", "DOM.Iterable"], "skipLibCheck": true, /* Bundler mode */ "moduleResolution": "bundler", "allowImportingTsExtensions": true, "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, "jsx": "preserve", /* Linting */ "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, /* Path aliases */ "baseUrl": ".", "paths": { "@/*": ["./src/*"], "@inc/*": ["../inc/*"] } }, "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"] } EOF # Create tsconfig.node.json for app echo " Creating tsconfig.node.json..." cat > "$HF_SPACE/trigo-web/app/tsconfig.node.json" << 'EOF' { "compilerOptions": { "composite": true, "skipLibCheck": true, "module": "ESNext", "moduleResolution": "bundler", "allowSyntheticDefaultImports": true }, "include": ["vite.config.ts"] } EOF # Patch package.json to skip type checking and add missing dependencies echo " Patching app/package.json..." cd "$HF_SPACE/trigo-web/app" # Remove vue-tsc from build script sed -i 's/"build": "vue-tsc --noEmit && vite build"/"build": "vite build"/' package.json # Add missing dependencies using jq (or sed if jq not available) if command -v jq &> /dev/null; then # Use jq for precise JSON editing jq '.dependencies["onnxruntime-web"] = "^1.23.2" | .devDependencies["@types/node"] = "^24.10.1"' package.json > package.json.tmp && mv package.json.tmp package.json else # Fallback: add dependencies manually if not present if ! grep -q '"onnxruntime-web"' package.json; then sed -i '/"dependencies": {/a \ "onnxruntime-web": "^1.23.2",' package.json fi if ! grep -q '"@types/node"' package.json; then sed -i '/"devDependencies": {/a \ "@types/node": "^24.10.1",' package.json fi fi cd "$HF_SPACE" echo "" echo "โœ… Files prepared and patched successfully!" echo "" echo "๐Ÿ“‹ Next steps:" echo " 1. cd $HF_SPACE" echo " 2. git add ." echo " 3. git commit -m 'Deploy Trigo game'" echo " 4. git push" echo "" echo "๐ŸŒ After pushing, HF will automatically build and deploy your app." echo ""