#!/usr/bin/env bash # Retakes an app's screenshots for cottondb.com from the app itself, with invented data, in one command: # # pnpm --filter @cottondb/site shots (e.g. days, words) # # 1. Walks the app on a throwaway Android emulator (pnpm android:walk, which builds the dev APK, boots, runs the # steps in tools/shots/.json and screenshots every step). Every word it types is made up, in that file. # 2. Keeps each step named `site-` as shots-src//.png; apps.json's `source` for that shot points there. # 3. Sizes them for the site (tools/site_pictures.py ). # 4. Says whether the app's words may be out of date: when its decisions or store text changed after the site's # words did, the page's words want a fresh writer from drafts/FACTS.md (README "Words"). set -euo pipefail app="${1:?usage: site_shots.sh }" SITE="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" ROOT="$(cd "$SITE/../.." && pwd)" steps="$SITE/tools/shots/$app.json" [ -f "$steps" ] || { echo "site_shots: no steps for $app at $steps" >&2; exit 2; } flavour=$(python3 -c 'import json,sys; a=[x for x in json.load(open(sys.argv[1]))["apps"] if x["id"]==sys.argv[2]]; print((a[0].get("android") or a[0]["id"]) if a else "")' "$SITE/apps.json" "$app") [ -n "$flavour" ] || { echo "site_shots: $app is not in apps.json" >&2; exit 2; } out="${SITE_SHOTS_OUT:-$(dirname "$ROOT")/walk/site-$app-$(date +%Y%m%d-%H%M%S)}" mkdir -p "$out" (cd "$ROOT" && pnpm -s android:walk "$flavour" --steps "$steps" --out "$out" --again) mkdir -p "$SITE/shots-src/$app" n=0 while IFS= read -r f; do name=$(basename "$f" .png); name=${name#*-site-} cp "$f" "$SITE/shots-src/$app/$name.png"; n=$((n + 1)); echo "kept $app/$name.png" done < <(find "$out" -name '*-site-*.png' | sort) [ "$n" -gt 0 ] || { echo "site_shots: the walk kept no site-* screenshot (see $out)" >&2; exit 1; } # SITE_PYTHON: a Python with Pillow, fontTools and brotli (the lane box keeps one in a venv). "${SITE_PYTHON:-python3}" "$SITE/tools/site_pictures.py" "$app" python3 - "$ROOT" "$app" <<'PY' import subprocess, sys root, app = sys.argv[1], sys.argv[2] def when(*paths): out = subprocess.run(["git", "-C", root, "log", "-1", "--format=%ct %cs", "--", *paths], capture_output=True, text=True).stdout.split() return (int(out[0]), out[1]) if out else (0, "never") design = {"words": "notes", "comms": "chat"}.get(app, app) words = when("apps/cotton-site/src/site/copy.ts", "apps/cotton-site/apps.json") for label, paths in (("its decisions", [f"assets/design/{design}/DECISIONS.md"]), ("its store text", [f"assets/store/appstore/{app}", f"assets/store/play/{app}"])): t = when(*paths) if t[0] > words[0]: print(f"site_shots: {app}'s {label} changed on {t[1]}, after the site's words ({words[1]}): read them, update drafts/FACTS.md, and have the page's words rewritten and checked.") PY echo "site_shots: $n screenshots for $app in shots-src/$app; point apps.json's shots at them (source) and build."