lmjtfy.git / tools / wrangler
wrangler27 lines · 1.3 KB · raw
1#!/usr/bin/env bash
2# wrangler, run in apps/lmjtfy, for the dev daemon and the deploy tasks.
3#
4#     tools/wrangler dev --port 8787
5#     tools/wrangler deploy --env staging
6#
7# It needs CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID in the environment (tools/with-secrets.sh
8# supplies them through fnox when that is set up). Where the owner's `lmjtfy-wrangler` is on PATH (the
9# credentialed wrapper from `nix develop .#owner`, which reads the token from 1Password per run) it is used
10# instead, and the environment needs nothing.
11#
12#     tools/wrangler --preflight       only check the credentials are there (exit 2 if not)
13set -euo pipefail
14cd "$(dirname "$0")/.."
15if [ "${1:-}" = "--preflight" ]; then
16  if command -v lmjtfy-wrangler >/dev/null 2>&1 || { [ -n "${CLOUDFLARE_API_TOKEN:-}" ] && [ -n "${CLOUDFLARE_ACCOUNT_ID:-}" ]; }; then
17    exit 0
18  fi
19  echo "CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID are not set: Workers AI has no local emulation, so wrangler needs your Cloudflare account even for dev. Export them, or set up fnox (fnox.toml)." >&2
20  exit 2
21fi
22if command -v lmjtfy-wrangler >/dev/null 2>&1; then
23  exec lmjtfy-wrangler apps/lmjtfy "$@"
24fi
25command -v wrangler >/dev/null 2>&1 || { echo "wrangler is not on PATH: run this through mise (mise run dev)" >&2; exit 1; }
26cd apps/lmjtfy
27exec wrangler "$@"