trigo / deploy.sh
k-l-lambda's picture
update
0b679f2
#!/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 ""