~james/core

core/web/scripts/deploy-cloudflare-preview.sh -rwxr-xr-x 1019 bytes
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 14 hours ago
                                                                                
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
#!/bin/sh
set -eu

cd "$(dirname "$0")/.."

name=$(sh scripts/preview-worker-name.sh)
worker="svfe-preview-$name"
host="$name.preview.tangled.org"
config="wrangler.preview.jsonc"

jq --arg worker "$worker" --arg host "$host" '
	.name = $worker
	| .workers_dev = false
	| del(.routes)
	| .routes = [{ pattern: $host, custom_domain: true }]
' wrangler.dev.jsonc >"$config"

jq -e --arg worker "$worker" --arg host "$host" '
	.name == $worker
	and .workers_dev == false
	and .routes == [{ pattern: $host, custom_domain: true }]
' "$config" >/dev/null || {
	echo "deploy-cloudflare-preview: refusing to deploy, $config did not come out clean" >&2
	cat "$config" >&2
	exit 1
}

export SVELTE_ADAPTER=cloudflare
export WRANGLER_CONFIG="$config"
export VITE_OAUTH_CLIENT_ID="https://$host/oauth-client-metadata.json"
export VITE_OAUTH_REDIRECT_URI="https://$host/oauth/callback"

# not `pnpm run build`, which needs bun
pnpm exec vite build
pnpm exec wrangler deploy --config "$config"

echo "preview deployed: https://$host"