setup

tcmts.examples.polls.setup · #yz4jjl4e · sh file

#!/bin/sh
# Build the polls example as a tcm codebase in <dir> (default ./polls-demo), then open <dir> in your editor.
# Uses the tcm on your PATH unless TCM is set (a command line for another one).
set -e
here=$(cd "$(dirname "$0")" && pwd)
dir=${1:-$PWD/polls-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 server API (tables, sessions, jobs): the library tcm ships, mounted read-only at polls.lib.server
tcm lib add tcm server --at polls.lib.server > /dev/null

# the code goes into the codebase file by file, as you'd add it from scratch files; then the files go away:
# from here on the code lives in .tcm, and the editor shows it from there
for f in model server ui; do
  cp "$here/$f.ts" .
  tcm add "$f.ts"
  rm "$f.ts"
done
cp "$here/playground.ts" scratch.ts
# (NO_TESTS=1 skips them: a server building it only to run it)
[ -n "${NO_TESTS:-}" ] || tcm test polls

cat <<MSG

The polls example is in $dir.
  tcm ls polls              what's in it
  tcm view polls.vote       a definition, with where it runs
  tcm dev polls.main        run the app (open the URL it prints)
Open $dir in VS Code (with the tcm-ts extension) to see it in the editor.
MSG

used by