File size: 4,019 Bytes
466436b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0b679f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
466436b
0b679f2
466436b
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/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 ""