setup
tcmts.examples.reminders.setup · #yh7wsexq · sh file
#!/bin/sh
# Build the reminders example as a tcm codebase in <dir> (default ./reminders-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 (and every other package the code imports) from its cache.
set -e
here=$(cd "$(dirname "$0")" && pwd)
dir=${1:-$PWD/reminders-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 and the icons: files kept in the codebase as they're written (the app imports the stylesheet, as a
# string; the pwa, the icons)
for file in styles.css icon.svg appicon.png; do cp "$here/$file" .; done
tcm add styles.css --into reminders
tcm add icon.svg --into reminders
tcm add appicon.png --into reminders
rm styles.css icon.svg appicon.png
# React's routes, links and stylesheets: the react library tcm ships, mounted read-only at reminders.lib.react
tcm lib add tcm react > /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.ts store.ts ui.tsx pwa.ts; do
cp "$here/$f" .
tcm add "$f"
rm "$f"
done
cp "$here/playground.ts" scratch.ts
[ -n "${NO_TESTS:-}" ] || tcm test reminders
cat <<MSG
The reminders example is in $dir.
tcm ls reminders what's in it
tcm view reminders.App the app, and why it runs in the browser
tcm dev reminders.App work on it (open the URL it prints)
tcm start reminders.App run it as it's deployed: installable, and offline once opened
tcm build reminders.App --static site a static site in site/, for any static host
Open $dir in VS Code (with the tcm-ts extension) to see it in the editor.
MSG
used by