Files
emdash-cms--emdash/scripts/sync-cloudflare-templates.sh
wehub-resource-sync b3a7f98e5a
CI / E2E Cloudflare (4/8) (push) Failing after 0s
CI / E2E Cloudflare (8/8) (push) Failing after 1s
CI / Lint (push) Failing after 1s
Auto Extract / Extract (push) Failing after 4s
CI / Version Check (push) Failing after 9s
CI / Integration Tests (push) Failing after 1s
CI / E2E tests (1/8) (push) Failing after 1s
CI / E2E tests (2/8) (push) Failing after 2s
CI / E2E tests (3/8) (push) Failing after 2s
CI / Browser Tests (push) Failing after 1s
CI / E2E tests (5/8) (push) Failing after 1s
CI / E2E Cloudflare (2/8) (push) Failing after 2s
CI / Typecheck (push) Failing after 1s
CI / Changeset Validation (push) Failing after 2s
CI / E2E Cloudflare (5/8) (push) Failing after 1s
CI / E2E Cloudflare (6/8) (push) Failing after 1s
CI / E2E Cloudflare (7/8) (push) Failing after 1s
CodeQL / Analyze (javascript-typescript) (push) Failing after 1s
Format / Format (push) Failing after 0s
CodeQL / Analyze (actions) (push) Failing after 4s
CI / E2E tests (4/8) (push) Failing after 1s
CI / E2E tests (6/8) (push) Failing after 1s
CI / E2E tests (7/8) (push) Failing after 2s
CI / E2E tests (8/8) (push) Failing after 1s
CI / E2E Cloudflare (1/8) (push) Failing after 1s
CI / E2E Cloudflare (3/8) (push) Failing after 2s
Preview Releases / Publish Preview (push) Failing after 0s
zizmor / Run zizmor (push) Failing after 1s
Release / Release (push) Failing after 2s
CI / Smoke Tests (push) Failing after 5m36s
CI / Tests (push) Failing after 6m36s
Release / Sync Templates (push) Has been skipped
CI / E2E Tests (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:23:53 +08:00

94 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
#
# Syncs shared files from base templates to their cloudflare variants.
# Run this after making changes to template src/, seed/, or tsconfig.json.
#
# Usage: ./scripts/sync-cloudflare-templates.sh
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(dirname "$SCRIPT_DIR")"
TEMPLATES_DIR="$ROOT_DIR/templates"
# Files/directories to sync from base template to cloudflare variant.
# .gitignore stays per-template: the cloudflare variants carry extra
# wrangler entries (.dev.vars) the base templates don't have.
SYNC_ITEMS=(
"src"
"public"
"seed"
"tsconfig.json"
"emdash-env.d.ts"
)
# Template pairs: base -> cloudflare variant
TEMPLATE_PAIRS=(
"blog:blog-cloudflare"
"marketing:marketing-cloudflare"
"portfolio:portfolio-cloudflare"
"starter:starter-cloudflare"
)
sync_template() {
local base="$1"
local variant="$2"
local base_dir="$TEMPLATES_DIR/$base"
local variant_dir="$TEMPLATES_DIR/$variant"
if [[ ! -d "$base_dir" ]]; then
echo " Skipping: $base (base not found)"
return
fi
if [[ ! -d "$variant_dir" ]]; then
echo " Skipping: $variant (variant not found)"
return
fi
echo "Syncing $base -> $variant"
for item in "${SYNC_ITEMS[@]}"; do
local src="$base_dir/$item"
local dest="$variant_dir/$item"
if [[ ! -e "$src" ]]; then
continue
fi
if [[ -d "$src" ]]; then
# Clean up if dest exists but isn't a directory
if [[ -L "$dest" || ( -e "$dest" && ! -d "$dest" ) ]]; then
rm "$dest"
fi
mkdir -p "$dest"
rsync -a --delete \
--exclude="worker.ts" \
"$src/" "$dest/"
echo " Synced directory: $item"
else
if [[ -L "$dest" ]]; then
rm "$dest"
elif [[ -d "$dest" ]]; then
rm -rf "$dest"
elif [[ -f "$dest" ]]; then
rm "$dest"
fi
cp "$src" "$dest"
echo " Copied file: $item"
fi
done
}
echo "Syncing cloudflare template variants..."
echo ""
for pair in "${TEMPLATE_PAIRS[@]}"; do
IFS=':' read -r base variant <<< "$pair"
sync_template "$base" "$variant"
echo ""
done
echo "Done!"