You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
4.0 KiB
Bash

#!/usr/bin/env bash
# Create a permanent overlay branch for a client: an orphan branch (no
# shared history with main) holding only what's unique to that client.
# export_client.sh merges it into the freshly-generated client/<slug>
# branch automatically if it exists.
#
# Usage: scripts/new_client_overlay.sh <client-slug>
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."
SLUG="${1:-}"
if [ -z "$SLUG" ]; then
echo "Usage: $0 <client-slug>"
exit 1
fi
BRANCH="overlay/${SLUG}"
if git show-ref --verify --quiet "refs/heads/${BRANCH}"; then
echo "${BRANCH} already exists."
exit 1
fi
if [ -n "$(git status --porcelain)" ]; then
echo "Working tree isn't clean. Commit or stash before creating an overlay."
exit 1
fi
CURRENT_BRANCH="$(git branch --show-current)"
git checkout -q --orphan "$BRANCH"
# Clears both the index AND the working tree of everything inherited from
# $CURRENT_BRANCH — safe, because `git rm` only ever touches tracked
# paths (node_modules/, .env, dist/ are gitignored, untouched either way).
# -f is required because there's no HEAD yet on a fresh orphan branch, so
# git has nothing to compare the index to and refuses without it. No
# error suppression: a real failure here should stop the script rather
# than silently commit all of main's files onto this branch.
git rm -rqf -- .
mkdir -p src/router/overlay
cat > "src/router/overlay/${SLUG}.tsx" <<EOF
/**
* Routes unique to ${SLUG} only. Picked up automatically by
* src/router/index.tsx via import.meta.glob("./overlay/*.tsx") — just
* export \`routes\`, nothing else to wire up.
*/
import type { RouteObject } from "react-router-dom";
export const routes: RouteObject[] = [
// { path: "/${SLUG}-custom", element: <YourPage /> },
];
EOF
git add "src/router/overlay/${SLUG}.tsx"
git commit -q -m "Start ${BRANCH} overlay"
echo "Created ${BRANCH}."
echo
echo "Add whatever's unique to ${SLUG} as NEW files only — never edit a file that"
echo "also exists on main. export_client.sh regenerates .env.example every run,"
echo "and every existing route/layout/style is main's, so there's no stable base"
echo "for a merge to reconcile against and it will conflict every time."
echo
echo "Extension points main already exposes (unused ones don't need touching):"
echo " src/router/overlay/${SLUG}.tsx routes — see the example added"
echo " src/shared/components/layouts/overlay/AppLayout.tsx"
echo " swap the whole app shell"
echo " (sidebar/navbar/colors)."
echo " Default export, same props"
echo " as DefaultAppLayout. Its mere"
echo " presence replaces the shell"
echo " for EVERY route, so only add"
echo " it once you have a real one —"
echo " that's why it's not scaffolded"
echo " here the way the routes file is."
echo " src/styles/overlay/*.css redefine index.css's :root/.dark"
echo " CSS variables (--primary, etc.)."
echo " Same caveat: any file here is"
echo " live the moment it exists."
echo " public/branding/${SLUG}/ new asset paths only — an"
echo " *existing* asset path (e.g."
echo " Logo_PLN.png) isn't safe to"
echo " override yet, see GIT_BRANCHES.md."
echo
echo "It's never merged into main and main is never merged into it — export_client.sh"
echo "merges it onto the disposable client/${SLUG} branch on every export instead."
git checkout -q "$CURRENT_BRANCH"