|
2 | 2 | # SPDX-License-Identifier: MPL-2.0 |
3 | 3 | # SPDX-FileCopyrightText: 2024-2026 Jonathan D.A. Jewell (hyperpolymath) |
4 | 4 | # |
5 | | -# cafe — CafeScripto shim. Forwards arguments to the affinescript CLI |
6 | | -# with --face cafe injected right after the subcommand. Source files |
7 | | -# should still use the canonical .affine extension and a face: cafescripto |
8 | | -# pragma; this shim only saves typing the --face flag for routine use. |
| 5 | +# cafe — CafeScripto shim (brand surface only; carries no compiler). |
| 6 | +# |
| 7 | +# Locates the canonical `affinescript` compiler and injects `--face cafe`. |
| 8 | +# Source files use the canonical `.affine` extension plus a `face: cafescripto` |
| 9 | +# pragma; this shim only saves typing the flag. Discovery order and the binding |
| 10 | +# contract are normative in docs/specs/FACE-CONTRACT.adoc (hyperpolymath/affinescript). |
| 11 | +set -euo pipefail |
| 12 | +FACE="cafe" |
| 13 | +BRAND="CafeScripto" |
| 14 | + |
| 15 | +# Resolve this script's own directory (follow symlinks) for sibling discovery. |
| 16 | +SOURCE="${BASH_SOURCE[0]}" |
| 17 | +while [ -h "$SOURCE" ]; do |
| 18 | + DIR="$(cd -P "$(dirname "$SOURCE")" >/dev/null 2>&1 && pwd)" |
| 19 | + SOURCE="$(readlink "$SOURCE")" |
| 20 | + [ "${SOURCE#/}" = "$SOURCE" ] && SOURCE="$DIR/$SOURCE" |
| 21 | +done |
| 22 | +SCRIPT_DIR="$(cd -P "$(dirname "$SOURCE")" >/dev/null 2>&1 && pwd)" |
| 23 | + |
| 24 | +find_affinescript() { |
| 25 | + # 1. explicit override |
| 26 | + if [ -n "${AFFINESCRIPT:-}" ] && [ -x "${AFFINESCRIPT:-}" ]; then |
| 27 | + printf '%s' "$AFFINESCRIPT"; return 0 |
| 28 | + fi |
| 29 | + # 2. on PATH (e.g. `opam install affinescript`) |
| 30 | + if command -v affinescript >/dev/null 2>&1; then |
| 31 | + printf '%s' affinescript; return 0 |
| 32 | + fi |
| 33 | + # 3. a sibling canonical checkout, built (`dune build`) |
| 34 | + local c |
| 35 | + for c in \ |
| 36 | + "$SCRIPT_DIR/../../γ-affinescript/affinescript/_build/default/bin/main.exe" \ |
| 37 | + "$SCRIPT_DIR/../../../γ-affinescript/affinescript/_build/default/bin/main.exe" \ |
| 38 | + "$SCRIPT_DIR/../affinescript/_build/default/bin/main.exe" \ |
| 39 | + "$HOME/developer/repos/γ-affinescript/affinescript/_build/default/bin/main.exe"; do |
| 40 | + if [ -x "$c" ]; then printf '%s' "$c"; return 0; fi |
| 41 | + done |
| 42 | + return 1 |
| 43 | +} |
| 44 | + |
| 45 | +if ! AS="$(find_affinescript)"; then |
| 46 | + cat >&2 <<MSG |
| 47 | +error: the canonical \`affinescript\` compiler was not found. |
| 48 | +$BRAND is a brand surface only — it needs the compiler installed. Try one of: |
| 49 | + • opam install affinescript (then re-run) |
| 50 | + • export AFFINESCRIPT=/path/to/affinescript |
| 51 | + • build a sibling checkout: (in γ-affinescript/affinescript) dune build |
| 52 | +See docs/specs/FACE-CONTRACT.adoc in hyperpolymath/affinescript. |
| 53 | +MSG |
| 54 | + exit 127 |
| 55 | +fi |
9 | 56 |
|
10 | 57 | if [ $# -eq 0 ]; then |
11 | | - exec affinescript |
| 58 | + exec "$AS" |
12 | 59 | fi |
13 | | -subcmd="$1" |
14 | | -shift |
15 | | -exec affinescript "$subcmd" --face cafe "$@" |
| 60 | +subcmd="$1"; shift |
| 61 | +exec "$AS" "$subcmd" --face "$FACE" "$@" |
0 commit comments