Setting the file. One moment. Deploy Codex · Deploy To Vercel · vercel-labs/agent-skills · Skills Docsresources/deploy-codex.sh
resources/deploy-codex.sh
Shell·301 lines·9 KB
15 if [ ! -f "$pkg_json" ]; then
16 echo "null"
17 return
18 fi
19
20 local content=$(cat "$pkg_json")
21
22 # Helper to check if a package exists in dependencies or devDependencies.
23 # Use exact matching by default, with a separate prefix matcher for scoped
24 # package families like "@remix-run/".
25 has_dep_exact() {
26 echo "$content" | grep -q "\"$1\""
27 }
28
29 has_dep_prefix() {
30 echo "$content" | grep -q "\"$1"
31 }
32
33 # Order matters - check more specific frameworks first
34
35 # Blitz
36 if has_dep_exact "blitz"; then echo "blitzjs"; return; fi
37
38 # Next.js
39 if has_dep_exact "next"; then echo "nextjs"; return; fi
40
41 # Gatsby
42 if has_dep_exact "gatsby"; then echo "gatsby"; return; fi
43
44 # Remix
45 if has_dep_prefix "@remix-run/"; then echo "remix"; return; fi
46
47 # React Router (v7 framework mode)
48 if has_dep_prefix "@react-router/"; then echo "react-router"; return; fi
49
50 # TanStack Start
51 if has_dep_exact "@tanstack/start"; then echo "tanstack-start"; return; fi
52
53 # Astro
54 if has_dep_exact "astro"; then echo "astro"; return; fi
55
56 # Hydrogen (Shopify)
57 if has_dep_exact "@shopify/hydrogen"; then echo "hydrogen"; return; fi
58
59 # SvelteKit
60 if has_dep_exact "@sveltejs/kit"; then echo "sveltekit-1"; return; fi
61
62 # Svelte (standalone)
63 if has_dep_exact "svelte"; then echo "svelte"; return; fi
64
65 # Nuxt
66 if has_dep_exact "nuxt"; then echo "nuxtjs"; return; fi
67
68 # Vue with Vitepress
69 if has_dep_exact "vitepress"; then echo "vitepress"; return; fi
70
71 # Vue with Vuepress
72 if has_dep_exact "vuepress"; then echo "vuepress"; return; fi
73
74 # Gridsome
75 if has_dep_exact "gridsome"; then echo "gridsome"; return; fi
76
77 # SolidStart
78 if has_dep_exact "@solidjs/start"; then echo "solidstart-1"; return; fi
79
80 # Docusaurus
81 if has_dep_exact "@docusaurus/core"; then echo "docusaurus-2"; return; fi
82
83 # RedwoodJS
84 if has_dep_prefix "@redwoodjs/"; then echo "redwoodjs"; return; fi
85
86 # Hexo
87 if has_dep_exact "hexo"; then echo "hexo"; return; fi
88
89 # Eleventy
90 if has_dep_exact "@11ty/eleventy"; then echo "eleventy"; return; fi
91
92 # Angular / Ionic Angular
93 if has_dep_exact "@ionic/angular"; then echo "ionic-angular"; return; fi
94 if has_dep_exact "@angular/core"; then echo "angular"; return; fi
95
96 # Ionic React
97 if has_dep_exact "@ionic/react"; then echo "ionic-react"; return; fi
98
99 # Create React App
100 if has_dep_exact "react-scripts"; then echo "create-react-app"; return; fi
101
102 # Ember
103 if has_dep_exact "ember-cli" || has_dep_exact "ember-source"; then echo "ember"; return; fi
104
105 # Dojo
106 if has_dep_exact "@dojo/framework"; then echo "dojo"; return; fi
107
108 # Polymer
109 if has_dep_prefix "@polymer/"; then echo "polymer"; return; fi
110
111 # Preact
112 if has_dep_exact "preact"; then echo "preact"; return; fi
113
114 # Stencil
115 if has_dep_exact "@stencil/core"; then echo "stencil"; return; fi
116
117 # UmiJS
118 if has_dep_exact "umi"; then echo "umijs"; return; fi
119
120 # Sapper (legacy Svelte)
121 if has_dep_exact "sapper"; then echo "sapper"; return; fi
122
123 # Saber
124 if has_dep_exact "saber"; then echo "saber"; return; fi
125
126 # Sanity
127 if has_dep_exact "sanity"; then echo "sanity-v3"; return; fi
128 if has_dep_prefix "@sanity/"; then echo "sanity"; return; fi
129
130 # Storybook
131 if has_dep_prefix "@storybook/"; then echo "storybook"; return; fi
132
133 # NestJS
134 if has_dep_exact "@nestjs/core"; then echo "nestjs"; return; fi
135
136 # Elysia
137 if has_dep_exact "elysia"; then echo "elysia"; return; fi
138
139 # Hono
140 if has_dep_exact "hono"; then echo "hono"; return; fi
141
142 # Fastify
143 if has_dep_exact "fastify"; then echo "fastify"; return; fi
144
145 # h3
146 if has_dep_exact "h3"; then echo "h3"; return; fi
147
148 # Nitro
149 if has_dep_exact "nitropack"; then echo "nitro"; return; fi
150
151 # Express
152 if has_dep_exact "express"; then echo "express"; return; fi
153
154 # Vite (generic - check last among JS frameworks)
155 if has_dep_exact "vite"; then echo "vite"; return; fi
156
157 # Parcel
158 if has_dep_exact "parcel"; then echo "parcel"; return; fi
159
160 # No framework detected
161 echo "null"
162}
163
164# Parse arguments
165INPUT_PATH="${1:-.}"
166
167# Create temp directory for packaging
168TEMP_DIR=$(mktemp -d)
169TARBALL="$TEMP_DIR/project.tgz"
170STAGING_DIR="$TEMP_DIR/staging"
171CLEANUP_TEMP=true
172
173cleanup() {
174 if [ "$CLEANUP_TEMP" = true ]; then
175 rm -rf "$TEMP_DIR"
176 fi
177}
178trap cleanup EXIT
179
180echo "Preparing deployment..." >&2
181
182# Check if input is a .tgz file or a directory
183FRAMEWORK="null"
184
185if [ -f "$INPUT_PATH" ] && [[ "$INPUT_PATH" == *.tgz ]]; then
186 # Input is already a tarball, use it directly
187 echo "Using provided tarball..." >&2
188 TARBALL="$INPUT_PATH"
189 CLEANUP_TEMP=false
190 # Can't detect framework from tarball, leave as null
191elif [ -d "$INPUT_PATH" ]; then
192 # Input is a directory, need to tar it
193 PROJECT_PATH=$(cd "$INPUT_PATH" && pwd)
194
195 # Detect framework from package.json
196 FRAMEWORK=$(detect_framework "$PROJECT_PATH/package.json")
197
198 # Stage files into a temporary directory to avoid mutating the source tree.
199 mkdir -p "$STAGING_DIR"
200 echo "Staging project files..." >&2
201 tar -C "$PROJECT_PATH" \
202 --exclude='node_modules' \
203 --exclude='.git' \
204 --exclude='.env' \
205 --exclude='.env.*' \
206 -cf - . | tar -C "$STAGING_DIR" -xf -
207
208 # Check if this is a static HTML project (no package.json)
209 if [ ! -f "$PROJECT_PATH/package.json" ]; then
210 # Find HTML files in root
211 HTML_FILES=$(find "$STAGING_DIR" -maxdepth 1 -name "*.html" -type f)
212 HTML_COUNT=$(printf '%s\n' "$HTML_FILES" | sed '/^$/d' | wc -l | tr -d '[:space:]')
213
214 # If there's exactly one HTML file and it's not index.html, rename it
215 if [ "$HTML_COUNT" -eq 1 ]; then
216 HTML_FILE=$(echo "$HTML_FILES" | head -1)
217 BASENAME=$(basename "$HTML_FILE")
218 if [ "$BASENAME" != "index.html" ]; then
219 echo "Renaming $BASENAME to index.html..." >&2
220 mv "$HTML_FILE" "$STAGING_DIR/index.html"
221 fi
222 fi
223 fi
224
225 # Create tarball from the staging directory
226 echo "Creating deployment package..." >&2
227 tar -czf "$TARBALL" -C "$STAGING_DIR" .
228else
229 echo "Error: Input must be a directory or a .tgz file" >&2
230 exit 1
231fi
232
233if [ "$FRAMEWORK" != "null" ]; then
234 echo "Detected framework: $FRAMEWORK" >&2
235fi
236
237# Deploy
238echo "Deploying..." >&2
239RESPONSE=$(curl -s -X POST "$DEPLOY_ENDPOINT" -F "file=@$TARBALL" -F "framework=$FRAMEWORK")
240
241# Check for error in response
242if echo "$RESPONSE" | grep -q '"error"'; then
243 ERROR_MSG=$(echo "$RESPONSE" | grep -o '"error":"[^"]*"' | cut -d'"' -f4)
244 echo "Error: $ERROR_MSG" >&2
245 exit 1
246fi
247
248# Extract URLs from response
249PREVIEW_URL=$(echo "$RESPONSE" | grep -o '"previewUrl":"[^"]*"' | cut -d'"' -f4)
250CLAIM_URL=$(echo "$RESPONSE" | grep -o '"claimUrl":"[^"]*"' | cut -d'"' -f4)
251
252if [ -z "$PREVIEW_URL" ]; then
253 echo "Error: Could not extract preview URL from response" >&2
254 echo "$RESPONSE" >&2
255 exit 1
256fi
257
258echo "Deployment started. Waiting for build to complete..." >&2
259echo "Preview URL: $PREVIEW_URL" >&2
260
261# Poll the preview URL until it returns a non-5xx response (5xx = still building)
262MAX_ATTEMPTS=60 # 5 minutes max (60 * 5 seconds)
263ATTEMPT=0
264
265while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
266 HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$PREVIEW_URL")
267
268 if [ "$HTTP_STATUS" -eq 200 ]; then
269 echo "" >&2
270 echo "Deployment ready!" >&2
271 break
272 elif [ "$HTTP_STATUS" -ge 500 ]; then
273 # 5xx means still building/deploying
274 echo "Building... (attempt $((ATTEMPT + 1))/$MAX_ATTEMPTS)" >&2
275 sleep 5
276 ATTEMPT=$((ATTEMPT + 1))
277 elif [ "$HTTP_STATUS" -ge 400 ] && [ "$HTTP_STATUS" -lt 500 ]; then
278 # 4xx might be an error or the app itself returns 4xx - it's responding
279 echo "" >&2
280 echo "Deployment ready (returned $HTTP_STATUS)!" >&2
281 break
282 else
283 # Any other status, assume it's ready
284 echo "" >&2
285 echo "Deployment ready!" >&2
286 break
287 fi
288done
289
290if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then
291 echo "" >&2
292 echo "Warning: Timed out waiting for deployment, but it may still be building." >&2
293fi
294
295echo "" >&2
296echo "Preview URL: $PREVIEW_URL" >&2
297echo "Claim URL: $CLAIM_URL" >&2
298echo "" >&2
299
300# Output JSON for programmatic use
301echo "$RESPONSE"