setup
tcmts.examples.effect.setup · #va2nvmzj · sh file
#!/bin/sh
# Build the Effect example in <dir> (default ./effect-demo): Effect 4.1.2, a large TypeScript library, imported from
# its npm package's source into a new codebase (with the few changes in changes.patch), and a playground using it.
# The import takes several minutes: it's about 15,000 definitions. Needs npm, to fetch the package.
# 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/effect-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
}
step() { printf '\n\033[1m%s\033[0m\n' "$*"; }
if [ -e "$dir/.tcm" ]; then echo "$dir already has a codebase" >&2; exit 1; fi
mkdir -p "$dir"
src=$(mktemp -d)
trap 'rm -rf "$src"' EXIT
step "Effect 4.1.2's source, from its npm package, with the changes in changes.patch"
(cd "$src" && npm pack effect@4.1.2 --silent > /dev/null && tar xzf effect-4.1.2.tgz)
(cd "$src/package" && patch -p0 -s < "$here/changes.patch")
# Effect's own compiler options (its repository's tsconfig.base.json, which the package doesn't ship)
cat > "$src/package/tsconfig.json" <<'JSON'
{
"include": ["src"],
"compilerOptions": {
"target": "ES2022",
"strict": true,
"exactOptionalPropertyTypes": true,
"noImplicitOverride": true,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true
}
}
JSON
cd "$dir"
step "A codebase, and Effect in it: a namespace per file (effect.Effect, effect.Schema, …), a definition per name"
tcm init > /dev/null
rm -f scratch.ts
# (left out: a module that's only there for its side effect, and the Scalar and Swagger pages, which load their
# bundled UIs with import())
tcm import "$src/package/src" --into effect \
--exclude schema/SchemaJITCompiler/enable.ts,http-api/HttpApiScalar.ts,http-api/HttpApiSwagger.ts,http-api/internal/httpApiScalar.ts,http-api/internal/httpApiSwagger.ts
step "The playground: programs using Effect, and their tests"
cp "$here/playground.ts" .
tcm add playground.ts
rm playground.ts
if [ -z "$NO_TESTS" ]; then tcm test demo; fi
tcm run demo.main
used by