Initial commit

This commit is contained in:
diyaa
2026-11-11 20:25:21 +01:00
commit 311f19f9d2
48 changed files with 1391 additions and 0 deletions
+73
View File
@@ -0,0 +1,73 @@
#!/usr/bin/env bash
# Shared build flow. Sourced by clean_rebuild.sh and dev_rebuild.sh.
# Expects: MODE (production|development), DO_CLEAN (1|0), PACKAGE_ONLY (1|0)
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT"
# shellcheck source=scripts/config.sh
source "$ROOT/scripts/config.sh"
log() { printf '==> %s\n' "$*"; }
fail() { printf 'ERROR: %s\n' "$*" >&2; exit 1; }
detect_pm() {
local dir="$1"
if [ -f "$dir/pnpm-lock.yaml" ]; then echo pnpm
elif [ -f "$dir/yarn.lock" ]; then echo yarn
elif [ -f "$dir/package-lock.json" ]; then echo npm
else fail "No lockfile in $dir. Commit a lockfile first (task T-006)."
fi
}
require_apps() {
for d in $APP_DIRS; do
[ -f "$d/package.json" ] || fail "$d/package.json does not exist yet. Create the project first (task T-006)."
done
}
install_deps() {
local d="$1" pm
pm="$(detect_pm "$d")"
command -v "$pm" >/dev/null 2>&1 || fail "$pm not found."
log "Installing dependencies in $d with $pm (frozen lockfile)"
case "$pm" in
npm) (cd "$d" && npm ci) ;;
pnpm) (cd "$d" && pnpm install --frozen-lockfile) ;;
yarn) (cd "$d" && yarn install --frozen-lockfile) ;;
esac
}
run_script() {
local d="$1" script="$2" pm
pm="$(detect_pm "$d")"
log "Running '$script' in $d"
(cd "$d" && "$pm" run "$script")
}
run_flow() {
require_apps
if [ "$DO_CLEAN" = "1" ]; then
log "Cleaning build output"
rm -rf web/.next api/dist
fi
for d in $APP_DIRS; do
if [ "$DO_CLEAN" = "1" ] || [ ! -d "$d/node_modules" ]; then
install_deps "$d"
fi
run_script "$d" build
done
[ -d web/.next ] || fail "web/.next was not produced."
[ -d api/dist ] || fail "api/dist was not produced."
if [ "$PACKAGE_ONLY" = "1" ]; then
log "Package-only mode: build verified, nothing started or deployed"
log "SUCCESS (build and verify only)"
return 0
fi
if [ "$MODE" = "development" ]; then
log "Build finished. Start the dev servers with: (cd web && npm run dev) and (cd api && npm run start:dev)"
else
log "Production build finished. Deploying is a separate step and only on the owner's request (task T-028)."
fi
log "SUCCESS"
}
+91
View File
@@ -0,0 +1,91 @@
#!/usr/bin/env bash
# Project invariants. Run by every make target before anything else.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT"
source "$ROOT/scripts/config.sh"
FAILS=0
ok() { printf 'ok %s\n' "$*"; }
bad() { printf 'FAIL %s\n' "$*" >&2; FAILS=$((FAILS + 1)); }
IN_GIT=0
git rev-parse --git-dir >/dev/null 2>&1 && IN_GIT=1
# 1. Shell scripts are executable and strict.
for f in clean_rebuild.sh dev_rebuild.sh scripts/*.sh; do
[ -x "$f" ] || bad "$f is not executable"
head -1 "$f" | grep -q '^#!' || bad "$f has no shebang"
grep -q 'set -euo pipefail' "$f" || bad "$f lacks 'set -euo pipefail'"
done
ok "scripts checked"
# 2. Lockfiles exist for every application that exists.
for d in $APP_DIRS; do
if [ -f "$d/package.json" ]; then
if [ -f "$d/package-lock.json" ] || [ -f "$d/pnpm-lock.yaml" ] || [ -f "$d/yarn.lock" ]; then
ok "$d lockfile present"
else
bad "$d has package.json but no lockfile"
fi
fi
done
# 3. Build output and secrets are git-ignored.
if [ -f .gitignore ]; then
for pat in node_modules .next dist .env; do
grep -qE "^/?(\*\*/)?${pat}/?$" .gitignore || bad ".gitignore does not ignore $pat"
done
ok ".gitignore checked"
else
bad ".gitignore is missing"
fi
if [ "$IN_GIT" = "1" ]; then
# 4. No .env file is tracked.
if git ls-files | grep -E '(^|/)\.env($|\.)' | grep -vE '\.env\.example$' | grep -q .; then
bad "a .env file is tracked by git"
else
ok "no .env tracked"
fi
# 5. No secret values in tracked files.
if git ls-files -z | xargs -0 grep -InE '(QF_CLIENT_SECRET|DATABASE_URL|POSTGRES_PASSWORD|JWT_SECRET)=[^[:space:]]+' 2>/dev/null \
| grep -vE '\.env\.example|docs/|AGENTS.md|scripts/check-invariants.sh' | grep -q .; then
bad "a secret-looking value is in a tracked file"
else
ok "no secret values in tracked files"
fi
fi
# 4b. Tracking scripts and third-party CDNs in the website source.
if [ -d web/src ] || [ -d web/app ]; then
if grep -rIlE 'googletagmanager|google-analytics|gtag\(|fbq\(|hotjar|plausible\.io|cdn\.jsdelivr|fonts\.googleapis' web/src web/app web/public 2>/dev/null | grep -q .; then
bad "tracking script or third-party CDN found in web sources"
else
ok "no tracking scripts or third-party CDNs"
fi
fi
# 5. Data-zone boundary: the public API must not touch qf_* data or the QF module.
if [ -d api/src/public ]; then
if grep -rInE "qf_|/qf/|from ['\"].*qf" api/src/public 2>/dev/null | grep -q .; then
bad "api/src/public references Quran Foundation data (qf_*)"
else
ok "public API does not touch qf_* data"
fi
fi
# 6. Compose files never publish ports directly (Traefik only).
if [ -d deploy ]; then
if grep -rnE '^\s*ports:' deploy/*.yml deploy/*.yaml 2>/dev/null | grep -q .; then
bad "a compose file publishes ports (use Traefik labels only)"
else
ok "compose files publish no ports"
fi
fi
if [ "$FAILS" -gt 0 ]; then
printf '\n%s invariant(s) failed.\n' "$FAILS" >&2
exit 1
fi
printf '\nAll invariants passed.\n'
+10
View File
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
# Shared settings. Sourced by the other scripts.
set -euo pipefail
SITE_NAME="quran-web"
SITE_HOST="quran.diyaa.de"
# Application folders, each with its own package.json and lockfile.
APP_DIRS="web api"
# Folders produced by builds (must be git-ignored).
BUILD_DIRS="web/.next api/dist node_modules"
+32
View File
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
# Lint, typecheck and tests for every application.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT"
source "$ROOT/scripts/config.sh"
log() { printf '==> %s\n' "$*"; }
fail() { printf 'ERROR: %s\n' "$*" >&2; exit 1; }
detect_pm() {
local dir="$1"
if [ -f "$dir/pnpm-lock.yaml" ]; then echo pnpm
elif [ -f "$dir/yarn.lock" ]; then echo yarn
elif [ -f "$dir/package-lock.json" ]; then echo npm
else fail "No lockfile in $dir."
fi
}
for d in $APP_DIRS; do
[ -f "$d/package.json" ] || fail "$d/package.json does not exist yet (task T-006)."
pm="$(detect_pm "$d")"
[ -d "$d/node_modules" ] || { log "Installing dependencies in $d"; (cd "$d" && "$pm" install --frozen-lockfile 2>/dev/null || (cd "$d" && npm ci)); }
for s in lint typecheck test; do
if (cd "$d" && node -e "process.exit(require('./package.json').scripts && require('./package.json').scripts['$s'] ? 0 : 1)"); then
log "Running '$s' in $d"
(cd "$d" && "$pm" run "$s")
else
fail "Script '$s' is missing in $d/package.json."
fi
done
done
log "SUCCESS (all checks passed)"