feat(website): crosscode website.sh and signing in through Accounts

crosscode: scripts/products/website.sh (ports 5300/3300, uploads in the
export), crosscode add <church> website (needs Accounts; www.<address>
or the Cross Code address), one install_app for Accounts and the
Website, env template copy, bats tests.

Backend: Hub client (protocol v2, product website), crosscode.link/1
with automatic connect to the church's Accounts, sign-in through
@crosscode/auth-client with the Website's own session and roles, the
first Owner from HUB_ADMIN_EMAIL (verified), 2FA for Owners and Admins,
back-channel logout, Accounts' user.* calls, and the church export.
Frontend: admin sign-in/out and the sign-in problem page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 09:27:07 +02:00
co-authored by Claude Opus 5.5
parent 79121bc447
commit 58960b5e93
43 changed files with 2361 additions and 77 deletions
+1 -1
View File
@@ -92,7 +92,7 @@ crosscode: Cross Code installs on this server ($(git -C "${CROSSCODE_FROM:-.}" r
crosscode deploy <church> … --check only the checks; changes nothing
crosscode status [<church>] versions, latest releases, health
crosscode install <church> --products events --domain <address> a new church
crosscode add <church> accounts [--domain …] add a product to a church here
crosscode add <church> accounts|website [--domain …] add a product to a church here
crosscode adopt <church> --events-dir <old folder> move an existing Cross Events install here
crosscode adopt <church> --undo go back to the old folder (within 14 days)
crosscode restart <church> [events] reload the PM2 processes
+3 -3
View File
@@ -8,7 +8,7 @@ CROSSCODE_REPO="${CROSSCODE_REPO:-https://c-git.crosscode.co.za/joshua/crosscode
# through it.
PRODUCT_ORDER=(accounts events website app)
# Products this version of the script can deploy (a products/<name>.sh exists for each).
SUPPORTED_PRODUCTS=(accounts events)
SUPPORTED_PRODUCTS=(accounts events website)
# Releases older than this get a warning; older than CROSSCODE_NODE_MIN the deploy is refused.
CROSSCODE_NODE_MIN=20
CROSSCODE_NODE_WARN=22
@@ -358,8 +358,8 @@ node_major() { node -p 'process.versions.node.split(".")[0]' 2>/dev/null || echo
# 1.0–1.1 has no .gitignore for its ecosystem.config.cjs). Nor do the files in the folders this
# script writes into (Accounts below 1.3.0 doesn't ignore the database dumps made before each
# deploy, so the dump would stop the very deploy that brings the .gitignore).
CROSSCODE_OWN_FILES=(apps/events/ecosystem.config.js apps/accounts/ecosystem.config.cjs)
CROSSCODE_OWN_DIRS=(apps/accounts/backend/backups/)
CROSSCODE_OWN_FILES=(apps/events/ecosystem.config.js apps/accounts/ecosystem.config.cjs apps/website/ecosystem.config.cjs)
CROSSCODE_OWN_DIRS=(apps/accounts/backend/backups/ apps/website/backend/backups/)
local_changes() {
git_in "$1" status --porcelain --untracked-files=all |
awk -v own="${CROSSCODE_OWN_FILES[*]}" -v dirs="${CROSSCODE_OWN_DIRS[*]}" '
+80 -45
View File
@@ -1,7 +1,8 @@
# shellcheck shell=bash
# crosscode install: a new church on this server (from hope-events' scripts/install.sh 2.1.x;
# behind frp from the Hub in agent 1.0, docs/AGENT-1.0-PLAN.md §7).
# Events only so far; Accounts, Website and App follow as their products/*.sh are added.
# A new church starts with Events or Accounts; the Website is added next to Accounts with
# `crosscode add` (WEBSITE-1.0-PLAN §11). The App follows as its products/app.sh is added.
install_usage() {
cat <<'EOF'
@@ -160,6 +161,21 @@ cmd_install() {
install_done "$church" "$product" "$pdomain" "$api" "$web" "$frp"
}
# Where a product goes on the church's address: <product>.<address>, except the Website, which is
# the church's own site: www.<address>, or the Cross Code address itself (hope.crosscode.co.za), as
# the Hub does (Hub 2.21.0).
default_domain() {
local product="$1" address="$2"
if [ "$product" = website ]; then
case "$address" in
*.crosscode.co.za) printf '%s' "$address" ;;
*) printf 'www.%s' "$address" ;;
esac
else
printf '%s.%s' "$product" "$address"
fi
}
# The checks every install and add share, before anything is touched.
install_check_options() {
local product="$1" ssl="$2" email="$3" version="$4" main="$5" frp="$6" api="$7" web="$8"
@@ -197,6 +213,7 @@ install_product() {
case "$product" in
events) install_events "$@" ;;
accounts) install_accounts "$@" ;;
website) install_website "$@" ;;
*) die "This version of crosscode can't install $product." ;;
esac
}
@@ -224,7 +241,10 @@ install_done() {
else
info "DNS (if not set yet): $domain → this server (A record, or a CNAME)."
fi
info "Open https://$domain/setup to create the admin account."
case "$product" in
website) info "Open https://$domain/admin and sign in with the admin email the Hub was given: that account becomes the first Owner." ;;
*) info "Open https://$domain/setup to create the admin account." ;;
esac
if [ "$product" = accounts ]; then info "Updates: crosscode deploy $church (Accounts is always updated first)"; else info "Updates: crosscode deploy $church $product"; fi
}
@@ -232,11 +252,13 @@ add_usage() {
cat <<'EOF'
crosscode add <church> <product> [options]
Adds a product to a church already installed here (from phase 3: Accounts next to Events), in
Adds a product to a church already installed here (Accounts next to Events, the Website next to
Accounts), in
its own folder, database, PM2 processes and site, run by the church's app user. If a step fails,
what this run made is removed again; the church's other products aren't touched.
--domain <domain> where it's served (default: <product>.<the church's address>)
--domain <domain> where it's served (default: <product>.<the church's address>; the
Website: www.<address>, or the address itself on a Cross Code address)
--version <product>@x.y.z that release (default: the latest)
--main the latest main (staging churches only)
--api-port <n> backend port (default: the first free one from 5000)
@@ -276,15 +298,17 @@ cmd_add() {
[ -n "$church" ] && [ -n "$product" ] || { add_usage; die "Name the church and the product."; }
valid_slug "$church" || die "\"$church\" isn't a church name."
is_known_product "$product" || die "Unknown product \"$product\"."
[ "$product" = events ] || [ "$product" = accounts ] || die "This version of crosscode can only add events and accounts."
case "$product" in events|accounts|website) ;; *) die "This version of crosscode can only add events, accounts and website." ;; esac
install_check_options "$product" "$ssl" "$email" "$version" "$main" "$frp" "$api" "$web"
require_root
load_church "$church"
! church_has_product "$product" || die "$church already has $product (crosscode status $church)."
# The Website signs in through the church's Accounts and can't be reached without it (WEBSITE-1.0-PLAN §11).
[ "$product" != website ] || church_has_product accounts || die "The Website needs the church's Accounts: add it first (crosscode add $church accounts)."
local address user="" existing
address="$(cenv ADDRESS)"
[ -n "$domain" ] || [ -n "$address" ] || die "--domain is needed: the church has no address in church.env."
domain="${domain:-$product.$address}"
domain="${domain:-$(default_domain "$product" "$address")}"
[[ "$domain" =~ ^[a-z0-9]([a-z0-9.-]*[a-z0-9])?\.[a-z]{2,}$ ]] || die "--domain: expected a domain."
[ ! -e "$(church_dir "$church")/$product" ] || die "$(church_dir "$church")/$product exists already. Move it away first."
# The church's app user: the one its other products run as.
@@ -422,24 +446,34 @@ install_events() {
die "The backend didn't answer with its version (sudo -u $user pm2 logs $name-backend)."
}
install_accounts() {
local church="$1" user="$2" domain="$3" api="$4" web="$5" version="$6" main="$7" ssl="$8" email="$9" frp="${10}"
local dir app db pass name ref
# shellcheck source=/dev/null
source "$CROSSCODE_HOME/products/accounts.sh"
dir="$(church_dir "$church")/accounts"
app="$dir/apps/accounts"
db="$(printf '%s_accounts' "$church" | tr '-' '_')"
name="$church-accounts"
church_env_set ACCOUNTS_DIR "$dir"
church_env_set ACCOUNTS_DOMAIN "$domain"
church_env_set ACCOUNTS_PM2 "$name-backend $name-frontend"
church_env_set ACCOUNTS_PORTS "$api $web"
church_env_set ACCOUNTS_DB "$db"
church_env_set ACCOUNTS_USER "$user"
[ "$frp" = 0 ] || church_env_set ACCOUNTS_FRP 1
install_accounts() { install_app accounts Accounts ACCOUNTS_SECRET "$@"; }
install_website() { install_app website Website WEBSITE_SECRET "$@"; }
step "Accounts: code ($dir)"
# install_app <product> <title> <generated secret> <church> <user> <domain> <api> <web> <version>
# <main> <ssl> <email> <frp>: Accounts and the Website (and later the App), which share one shape:
# a checkout of crosscode-platform, apps/<product>/{backend,frontend}, ecosystem.config.cjs, and
# one secret generated here that never leaves the server.
install_app() {
local product="$1" title="$2" secret="$3"
shift 3
local church="$1" user="$2" domain="$3" api="$4" web="$5" version="$6" main="$7" ssl="$8" email="$9" frp="${10}"
local dir app db pass name ref prefix
# shellcheck source=/dev/null
source "$CROSSCODE_HOME/products/$product.sh"
prefix="$(printf '%s' "$product" | tr '[:lower:]' '[:upper:]')"
dir="$(church_dir "$church")/$product"
app="$dir/apps/$product"
db="$(printf '%s_%s' "$church" "$product" | tr '-' '_')"
name="$church-$product"
church_env_set "${prefix}_DIR" "$dir"
church_env_set "${prefix}_DOMAIN" "$domain"
church_env_set "${prefix}_PM2" "$name-backend $name-frontend"
church_env_set "${prefix}_PORTS" "$api $web"
church_env_set "${prefix}_DB" "$db"
church_env_set "${prefix}_USER" "$user"
[ "$frp" = 0 ] || church_env_set "${prefix}_FRP" 1
step "$title: code ($dir)"
mkdir -p "$dir"
undo_add dir "$dir"
chown "$user:$user" "$dir"
@@ -448,63 +482,64 @@ install_accounts() {
if [ "$main" = 1 ]; then
version=origin/main
elif [ -z "$version" ]; then
version="$(latest_tag "$dir" accounts)"
[ -n "$version" ] || die "No accounts@x.y.z release tags yet (use --version or --main)."
version="$(latest_tag "$dir" "$product")"
[ -n "$version" ] || die "No $product@x.y.z release tags yet (use --version or --main)."
fi
run_as "$user" "$dir" git checkout -q --detach "$version"
ref="$(checkout_ref "$dir" accounts)"
ref="$(checkout_ref "$dir" "$product")"
info "At $ref"
report_result_json versions "{\"accounts\":\"$ref\"}"
report_result_json versions "{\"$product\":\"$ref\"}"
step "Accounts: database ($db on $(db_host))"
step "$title: database ($db on $(db_host))"
! db_exists "$db" || die "A database or role named $db already exists on $(db_host). Remove it first if it's left over, or choose another church name."
pass="$(random_secret 32)"
undo_add db "$db"
db_create "$db" "$pass"
step "Accounts: configuration"
step "$title: configuration"
local trust=1
[ "$frp" = 0 ] || trust=loopback
(
export CROSSCODE_GEN_NODE_ENV=production
export CROSSCODE_GEN_ACCOUNTS_SECRET
CROSSCODE_GEN_ACCOUNTS_SECRET="$(random_secret 64)"
local generated
generated="$(random_secret 64)"
export "CROSSCODE_GEN_$secret=$generated"
export CROSSCODE_GEN_DATABASE_URL="postgresql://$db:$pass@$(db_host):$(db_port)/$db"
env_apply "$app" accounts "$ref" --var "domain=$domain" --var "apiPort=$api" --var "webPort=$web" --var "church=$church" \
env_apply "$app" "$product" "$ref" --var "domain=$domain" --var "apiPort=$api" --var "webPort=$web" --var "church=$church" \
--fallback "TRUST_PROXY=$trust"
) | sed 's/^/ /'
[ "${PIPESTATUS[0]}" = 0 ] || die "The .env files couldn't be written (see above)."
chown "$user:$user" "$app/backend/.env" "$app/frontend/.env.production"
chmod 600 "$app/backend/.env" "$app/frontend/.env.production"
accounts_ensure_pm2_config "$dir" "$user"
"${product}_ensure_pm2_config" "$dir" "$user"
step "Accounts: install, migrate, build"
accounts_install_deps "$dir" "$user"
accounts_migrate "$dir" "$user"
accounts_build "$dir" "$user"
step "$title: install, migrate, build"
"${product}_install_deps" "$dir" "$user"
"${product}_migrate" "$dir" "$user"
"${product}_build" "$dir" "$user"
step "Accounts: PM2"
step "$title: PM2"
undo_add pm2 "$user" "$name-backend $name-frontend"
run_as "$user" "$app" pm2 startOrReload ecosystem.config.cjs
run_as "$user" "$app" pm2 save
if [ "$frp" = 1 ]; then
step "Accounts: frpc tunnels"
frpc_add "$church" accounts "$web" "$api"
undo_add frpc "$church" accounts
step "$title: frpc tunnels"
frpc_add "$church" "$product" "$web" "$api"
undo_add frpc "$church" "$product"
frpc_reload
else
step "Accounts: nginx ($domain)"
step "$title: nginx ($domain)"
install_site_nginx "$name" "$domain" "$api" "$web"
undo_add nginx "$name"
if [ "$ssl" = 1 ]; then
step "Accounts: certificate"
step "$title: certificate"
certbot --nginx -d "$domain" --non-interactive --agree-tos -m "$email" --redirect
fi
fi
step "Accounts: checking it answers"
wait_for_version "$(accounts_health_url)" "$(accounts_expected_version "$dir")" 90 ||
step "$title: checking it answers"
wait_for_version "$("${product}_health_url")" "$("${product}_expected_version" "$dir")" 90 ||
die "The backend didn't answer with its version (sudo -u $user pm2 logs $name-backend)."
}
@@ -0,0 +1,24 @@
{
"schema": "crosscode.env-template/1",
"product": "website",
"files": {
"backend/.env": [
{ "name": "NODE_ENV", "layer": "generated", "required": true, "description": "production" },
{ "name": "PORT", "layer": "install", "from": "{apiPort}", "required": true, "description": "The backend's port (from the Hub's port list)" },
{ "name": "DATABASE_URL", "layer": "generated", "required": true, "description": "Made on the server with a new password; never leaves it" },
{ "name": "WEBSITE_SECRET", "layer": "generated", "required": true, "description": "Signs preview links and cookies, encrypts stored secrets: never change it" },
{ "name": "WEBSITE_URL", "layer": "install", "from": "https://{domain}", "required": true, "description": "The public address (www. or the Cross Code address)" },
{ "name": "TRUST_PROXY", "layer": "server", "required": true, "description": "Behind frp: loopback" },
{ "name": "APP_TIMEZONE", "layer": "install", "default": "Africa/Johannesburg" },
{ "name": "HUB_URL", "layer": "defaults", "default": "https://hub.crosscode.co.za" },
{ "name": "HUB_PUBLIC_KEY", "layer": "defaults", "description": "Only for a Hub other than production" },
{ "name": "HUB_LICENCE_KEY", "layer": "install", "description": "A Hub install registers by itself with this (CCW-…)" },
{ "name": "HUB_ADMIN_NAME", "layer": "install" },
{ "name": "HUB_ADMIN_EMAIL", "layer": "install", "description": "The first person to sign in with this address (through Accounts, verified) becomes the Owner" },
{ "name": "JOBS_ENABLED", "layer": "defaults", "default": "true" }
],
"frontend/.env.production": [
{ "name": "WEBSITE_API_URL", "layer": "install", "from": "http://127.0.0.1:{apiPort}", "required": true, "description": "Where the pages reach the backend on this server" }
]
}
}
+138
View File
@@ -0,0 +1,138 @@
# shellcheck shell=bash
# The Church Website's hooks for the crosscode script (docs/WEBSITE-1.0-PLAN.md §11), the same
# hooks as products/accounts.sh. Every hook takes the product's checkout (WEBSITE_DIR, a checkout of
# crosscode-platform) and the app user. Values come from church.env (CENV): WEBSITE_DIR,
# WEBSITE_DOMAIN, WEBSITE_PM2 ("<backend> <frontend>"), WEBSITE_PORTS ("<api> <web>"),
# WEBSITE_DB, WEBSITE_USER.
website_app() { printf '%s/apps/website' "$1"; }
website_pm2_names() { pvar website PM2; }
website_api_port() { local p; read -r p _ <<< "$(pvar website PORTS)"; printf '%s' "${p:-5300}"; }
website_web_port() { local p; read -r _ p <<< "$(pvar website PORTS)"; printf '%s' "${p:-3300}"; }
website_health_url() { printf 'http://127.0.0.1:%s/api/health' "$(website_api_port)"; }
website_expected_version() {
node -p 'require(process.argv[1]).version' "$(website_app "$1")/backend/package.json"
}
# The shared packages the Website is built with (contracts, auth-client for signing in, ui for its pages).
website_shared_packages() {
local p
for p in packages/contracts packages/ui packages/auth-client; do
[ -f "$1/$p/package.json" ] && printf '%s\n' "$p"
done
}
# A database dump into backend/backups/ (the last 14 are kept), before every deploy and uninstall.
website_backup() {
local dir="$1" user="$2" backend
backend="$(website_app "$dir")/backend"
# shellcheck disable=SC2016 # the app user's shell expands these
run_as "$user" "$backend" bash -c '
set -euo pipefail
url="$(grep -E "^DATABASE_URL=" .env | head -1 | cut -d= -f2- | sed -e "s/^\"//" -e "s/\"$//")"
mkdir -p backups
file="backups/website-$(date +%Y%m%d-%H%M%S).sql.gz"
pg_dump --no-owner --no-privileges "$url" | gzip > "$file"
chmod 600 "$file"
ls -1t backups/website-*.sql.gz | tail -n +15 | xargs -r rm -f
echo " $file"'
}
website_install_deps() {
local -a ws=()
local p
while IFS= read -r p; do ws+=(-w "$p"); done < <(website_shared_packages "$1")
run_as "$2" "$1" npm ci --include=dev --no-audit --no-fund --include-workspace-root "${ws[@]}" -w apps/website/backend -w apps/website/frontend
}
website_migrate() {
run_as "$2" "$(website_app "$1")/backend" npm run prisma:deploy
}
website_build() {
local p
for p in packages/contracts packages/auth-client; do
[ ! -f "$1/$p/package.json" ] || run_as "$2" "$1/$p" npm run build || return 1
done
run_as "$2" "$(website_app "$1")/backend" npm run build &&
run_as "$2" "$(website_app "$1")/frontend" npm run build
}
website_rollback_build() {
website_install_deps "$1" "$2" && website_build "$1" "$2"
}
# The install's own PM2 config (not in git), made from the example the first time.
website_ensure_pm2_config() {
local dir="$1" user="$2" app conf backend frontend
app="$(website_app "$dir")"
conf="$app/ecosystem.config.cjs"
[ -f "$conf" ] && return 0
read -r backend frontend <<< "$(website_pm2_names)"
sed -e "s/'website-backend'/'${backend}'/" \
-e "s/'website-frontend'/'${frontend}'/" \
-e "s/-p 3300/-p $(website_web_port)/" \
"$app/ecosystem.config.example.cjs" > "$conf"
chown "$user:$user" "$conf" 2>/dev/null || true
info "Created $conf from the example."
}
website_reload() {
website_ensure_pm2_config "$1" "$2"
run_as "$2" "$(website_app "$1")" pm2 reload ecosystem.config.cjs --update-env
}
# export.json (crosscode.church-export/1 with its `website` part: pages, messages, events, media,
# the editors; no secrets) into <out dir>. The uploads are copied by website_copy_uploads.
website_export() {
local app
app="$(website_app "$1")"
run_as "$2" "$app/backend" npx tsx scripts/export-church.ts --out-dir "$3"
}
# The church's uploads (photos, documents) into <out dir>, as Events' copy_uploads.
website_copy_uploads() {
local uploads
uploads="$(website_app "$1")/backend/uploads"
mkdir -p "$2"
[ ! -d "$uploads" ] || rsync -a "$uploads/" "$2/"
}
# What uninstall keeps for 30 days: the backups and the .env (its WEBSITE_SECRET decrypts what's stored).
website_keep() {
local app dest="$2"
app="$(website_app "$1")"
mkdir -p "$dest"
[ ! -d "$app/backend/backups" ] || rsync -a "$app/backend/backups/" "$dest/backups/"
cp -p "$app/backend/.env" "$dest/backend.env" 2>/dev/null || true
chmod -R go-rwx "$dest"
}
website_env_vars() {
printf '%s\n' --var "domain=$(pvar website DOMAIN)" --var "apiPort=$(website_api_port)" --var "webPort=$(website_web_port)" --var "church=$(cenv CHURCH)"
}
# As events_resolve_failed_migrations: a migration that failed in this release and isn't in the
# previous one is marked as rolled back (the backup taken first has the database as it was).
website_resolve_failed_migrations() {
local dir="$1" user="$2" prev="$3" backend name
backend="$(website_app "$dir")/backend"
local -a failed
# shellcheck disable=SC2016 # SQL through psql, run as the app user
mapfile -t failed < <(run_as "$user" "$backend" bash -c '
url="$(grep -E "^DATABASE_URL=" .env | head -1 | cut -d= -f2- | sed -e "s/^\"//" -e "s/\"$//")"
psql "$url" -At -c "select migration_name from _prisma_migrations where finished_at is null and rolled_back_at is null"')
for name in "${failed[@]}"; do
[ -n "$name" ] || continue
if git_in "$dir" cat-file -e "$prev:apps/website/backend/prisma/migrations/$name/migration.sql" 2>/dev/null; then
warn "website: $name failed but $prev has it too; left for a look (npx prisma migrate status)."
continue
fi
run_as "$user" "$backend" npx prisma migrate resolve --rolled-back "$name" >/dev/null
info "website: marked the failed migration $name as rolled back."
report_result "resolvedMigration" "$name"
done
}
+6 -2
View File
@@ -105,9 +105,13 @@ setup() {
[ "$status" -eq 1 ]
[[ "$output" == *"Name the church and the product"* ]]
run bash "$CC" add hope website --no-ssl
run bash "$CC" add hope app --no-ssl
[ "$status" -eq 1 ]
[[ "$output" == *"can only add events and accounts"* ]]
[[ "$output" == *"can only add events, accounts and website"* ]]
run bash "$CC" add hope website
[ "$status" -eq 1 ]
[[ "$output" == *"--email is required"* ]]
run bash "$CC" add hope accounts
[ "$status" -eq 1 ]
+83
View File
@@ -0,0 +1,83 @@
#!/usr/bin/env bats
# The Church Website's hooks that don't need a server (WEBSITE-1.0-PLAN §11), and where `crosscode
# add` puts it on the church's address. Run with `npm run test:scripts`.
setup() {
# shellcheck source=../lib/common.sh
source "$BATS_TEST_DIRNAME/../lib/common.sh"
# shellcheck source=../lib/install.sh
source "$BATS_TEST_DIRNAME/../lib/install.sh"
# shellcheck source=../products/website.sh
source "$BATS_TEST_DIRNAME/../products/website.sh"
TMP="$BATS_TEST_TMPDIR"
CALLS="$TMP/calls"
: > "$CALLS"
# Record what would run, as the app user, instead of running it.
run_as() { local user="$1" dir="$2"; shift 2; echo "$user|${dir#"$TMP"/}|$*" >> "$CALLS"; }
CENV=()
}
checkout() {
local dir="$TMP/$1" p
for p in contracts ui auth-client; do
mkdir -p "$dir/packages/$p"
echo "{\"name\":\"@crosscode/$p\"}" > "$dir/packages/$p/package.json"
done
mkdir -p "$dir/apps/website/backend" "$dir/apps/website/frontend"
echo '{"version":"1.0.0"}' > "$dir/apps/website/backend/package.json"
cp "$BATS_TEST_DIRNAME/../../apps/website/ecosystem.config.example.cjs" "$dir/apps/website/"
}
@test "the Website goes on www., or on the Cross Code address itself; other products on <product>." {
[ "$(default_domain website hopefamily.co.za)" = www.hopefamily.co.za ]
[ "$(default_domain website hope.crosscode.co.za)" = hope.crosscode.co.za ]
[ "$(default_domain events hopefamily.co.za)" = events.hopefamily.co.za ]
[ "$(default_domain accounts hope.crosscode.co.za)" = accounts.hope.crosscode.co.za ]
}
@test "the Website is a product this script deploys" {
is_supported_product website
}
@test "contracts, ui and auth-client are installed; contracts and auth-client built before the Website" {
checkout new
website_install_deps "$TMP/new" hope
grep -qx 'hope|new|npm ci --include=dev --no-audit --no-fund --include-workspace-root -w packages/contracts -w packages/ui -w packages/auth-client -w apps/website/backend -w apps/website/frontend' "$CALLS"
: > "$CALLS"
website_build "$TMP/new" hope
[ "$(cut -d'|' -f2 "$CALLS" | tr '\n' ' ')" = "new/packages/contracts new/packages/auth-client new/apps/website/backend new/apps/website/frontend " ]
}
@test "ports default to 5300 / 3300, else church.env's" {
[ "$(website_api_port)" = 5300 ]
[ "$(website_web_port)" = 3300 ]
church_env_set WEBSITE_PORTS "5410 3410"
[ "$(website_health_url)" = http://127.0.0.1:5410/api/health ]
[ "$(website_web_port)" = 3410 ]
}
@test "the PM2 config is made once, with the church's names and port" {
checkout new
church_env_set WEBSITE_PM2 "hope-website-backend hope-website-frontend"
church_env_set WEBSITE_PORTS "5410 3410"
info() { :; }
website_ensure_pm2_config "$TMP/new" "$(id -un)"
conf="$TMP/new/apps/website/ecosystem.config.cjs"
grep -q "'hope-website-backend'" "$conf"
grep -q "'hope-website-frontend'" "$conf"
grep -q -- "-p 3410" "$conf"
echo changed > "$conf"
website_ensure_pm2_config "$TMP/new" "$(id -un)"
[ "$(cat "$conf")" = changed ]
}
@test "the uploads are copied into the export; none is fine" {
command -v rsync >/dev/null || skip "rsync isn't installed here"
checkout new
website_copy_uploads "$TMP/new" "$TMP/out1"
[ -d "$TMP/out1" ]
mkdir -p "$TMP/new/apps/website/backend/uploads/2026"
echo jpg > "$TMP/new/apps/website/backend/uploads/2026/hero.jpg"
website_copy_uploads "$TMP/new" "$TMP/out2"
[ "$(cat "$TMP/out2/2026/hero.jpg")" = jpg ]
}