setup

tcmts.examples.userinput.setup · #ceybpgbh · sh file

#!/bin/sh
# Build the userinput example as a tcm codebase in <dir> (default ./userinput-demo), then open <dir> in your editor.
# Uses the tcm on your PATH unless TCM is set (a command line for another one). Nothing to install: tcm provides
# React, React Aria and the AT Protocol libraries (every package the code imports) from its cache.
set -e
here=$(cd "$(dirname "$0")" && pwd)
dir=${1:-$PWD/userinput-demo}
# a function, not a variable: this checkout's path may contain spaces. TCM_BIN (a tcm.js to run with Node) is
# what the test suites set.
tcm() {
  if [ -n "$TCM_BIN" ]; then node "$TCM_BIN" "$@"
  elif [ -n "$TCM" ]; then $TCM "$@"
  else command tcm "$@"; fi
}

if [ -e "$dir/.tcm" ]; then echo "$dir already has a codebase" >&2; exit 1; fi
mkdir -p "$dir"
cd "$dir"
tcm init > /dev/null
rm -f scratch.ts

# the look: a stylesheet, kept in the codebase as it's written (the app puts it in the page)
cp "$here/styles.css" .
tcm add styles.css --into userinput.design
rm styles.css

# React's routes, links and data: the react library tcm ships, mounted read-only at userinput.lib.react
tcm lib add tcm react > /dev/null

# the code, file by file, each after what it uses, as you'd add it from scratch files; then the files go away:
# from here on the code lives in .tcm
for f in model.ts network.ts rules.ts data.ts session.ts writes.ts design.tsx markdown.tsx home.tsx board.tsx discussion.tsx people.tsx app.tsx; do
  cp "$here/$f" .
  tcm add "$f"
  rm "$f"
done
# (NO_TESTS=1 skips them: a server building it only to run it, with no browser for the one that needs it)
[ -n "${NO_TESTS:-}" ] || tcm test userinput

cat <<MSG

The userinput example is in $dir: a client for userinput.app, feedback boards on the AT Protocol.
  tcm ls userinput                  what's in it
  tcm view userinput.authorityOf    who a space's moderation counts from
  tcm dev userinput.app.App         run it (open the URL it prints, and sign in with your Bluesky handle)
Open $dir in VS Code (with the tcm-ts extension) to see it in the editor.
MSG

used by