1#!/usr/bin/env bash 2# What `wrangler dev` and `wrangler deploy` run before they serve or upload (worker/wrangler.toml, 3# [build]): the Worker, and the link preview's PNG and MP4, so a Worker cannot go out whose 4# own meta tags point at files that were never made. 5# 6# Run inside `nix develop ~/whiskers#web`. 7set -euo pipefail 8here="$(cd "$(dirname "$0")/.." && pwd)" 9cd "$here" 10 11out=worker/public/preview 12 13# The preview (the default mascot, Ginger) is rebuilt when a file is missing or the hash of what it 14# is drawn from has changed (tools/preview-hash: content, not modification times). It takes about 15# fifteen seconds; `wrangler dev` runs this on every save, so an unchanged source costs a hash. 16stale=0 17if [ ! -f "$out/card.png" ] || [ ! -f "$out/loop.mp4" ] || [ ! -f "$out/.sources" ]; then 18 stale=1 19elif [ "$(tools/preview-hash)" != "$(cat "$out/.sources")" ]; then 20 stale=1 21fi 22if [ "$stale" = 1 ]; then 23 rm -f "$out/card.png" "$out/loop.mp4" 24 tools/preview "$out" 25 tools/check-preview "$out" 26fi 27 28cd worker 29exec worker-build --release