diff --git a/scripts/ci/sync-to-gitlab.sh b/scripts/ci/sync-to-gitlab.sh new file mode 100755 index 00000000..e99ea1f6 --- /dev/null +++ b/scripts/ci/sync-to-gitlab.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env bash +# sync-to-gitlab.sh — copy source from this repo to a target deployment dir. +# +# Usage: sync-to-gitlab.sh +# +# Same logic as scripts/sync-to-flights-front.sh, but takes the target as a +# required argument and emits machine-friendly output (no "next steps" hints). +set -euo pipefail + +SRC_DIR="$(cd "$(dirname "$0")/../.." && pwd)" +TARGET_DIR="${1:-}" + +if [ -z "$TARGET_DIR" ]; then + echo "usage: $0 " >&2 + exit 2 +fi +if [ ! -d "$TARGET_DIR" ]; then + echo "fatal: target directory does not exist: $TARGET_DIR" >&2 + exit 1 +fi + +DEPLOY_ROOT="$(cd "$TARGET_DIR/.." && pwd)" + +echo "syncing $SRC_DIR → $TARGET_DIR" + +# 1. Clean target (preserve node_modules, .git, .dockerignore) +find "$TARGET_DIR" -mindepth 1 -maxdepth 1 \ + ! -name "node_modules" \ + ! -name ".dockerignore" \ + ! -name ".git" \ + -exec rm -rf {} + + +# 2. Copy source files +cp -r "$SRC_DIR/src" "$TARGET_DIR/src" +cp -r "$SRC_DIR/tests" "$TARGET_DIR/tests" +cp -r "$SRC_DIR/scripts" "$TARGET_DIR/scripts" +cp -r "$SRC_DIR/config" "$TARGET_DIR/config" +cp "$SRC_DIR/package.json" "$TARGET_DIR/package.json" +cp "$SRC_DIR/pnpm-lock.yaml" "$TARGET_DIR/pnpm-lock.yaml" +cp "$SRC_DIR/tsconfig.json" "$TARGET_DIR/tsconfig.json" +cp "$SRC_DIR/modern.config.ts" "$TARGET_DIR/modern.config.ts" +cp "$SRC_DIR/module-federation.config.ts" "$TARGET_DIR/module-federation.config.ts" +cp "$SRC_DIR/vitest.config.ts" "$TARGET_DIR/vitest.config.ts" +cp "$SRC_DIR/playwright.config.ts" "$TARGET_DIR/playwright.config.ts" +cp "$SRC_DIR/eslint.config.js" "$TARGET_DIR/eslint.config.js" +cp "$SRC_DIR/Makefile" "$TARGET_DIR/Makefile" +cp "$SRC_DIR/CLAUDE.md" "$TARGET_DIR/CLAUDE.md" +cp "$SRC_DIR/AGENTS.md" "$TARGET_DIR/AGENTS.md" + +# Customer-specific Dockerfile (different defaults than ours) +cp "$SRC_DIR/Dockerfile.react" "$TARGET_DIR/Dockerfile" + +# 3. Copy deployment configs alongside the app +if [ -d "$SRC_DIR/deployment" ]; then + mkdir -p "$DEPLOY_ROOT/deployment" + cp -R "$SRC_DIR/deployment/." "$DEPLOY_ROOT/deployment/" +fi + +# 4. Cleanup artifacts that shouldn't ship +find "$TARGET_DIR" -maxdepth 1 -name "*.png" -delete 2>/dev/null || true +rm -rf "$TARGET_DIR/src/server/middleware/"*.test.ts 2>/dev/null || true +rm -f "$TARGET_DIR/scripts/sync-to-flights-front.sh" 2>/dev/null || true +rm -rf "$TARGET_DIR/scripts/ci" 2>/dev/null || true # our pipeline scripts; not for customer +rm -rf "$TARGET_DIR/scripts/phase-0" 2>/dev/null || true +rm -f "$TARGET_DIR/scripts/screenshot-diff.ts" 2>/dev/null || true +rm -f "$TARGET_DIR/playwright-angular.config.ts" 2>/dev/null || true +rm -rf "$TARGET_DIR/tests/e2e-angular" 2>/dev/null || true +rm -rf "$TARGET_DIR/tests/parity" 2>/dev/null || true +rm -rf "$TARGET_DIR/tests/ci" 2>/dev/null || true # our bash unit tests; not for customer +rm -rf "$TARGET_DIR/.gitea" 2>/dev/null || true # our workflows; not for customer +rm -rf "$TARGET_DIR/docs/superpowers" 2>/dev/null || true + +# 5. Ensure .dockerignore exists at target +if [ ! -f "$TARGET_DIR/.dockerignore" ]; then + cat > "$TARGET_DIR/.dockerignore" <<'EOF' +node_modules +dist +coverage +test-results +playwright-report +.playwright-mcp +*.png +*.md +.git +.claude +.gstack +EOF +fi + +echo "ok: sync complete" diff --git a/scripts/sync-to-flights-front.sh b/scripts/sync-to-flights-front.sh index dad4fb52..6772b087 100755 --- a/scripts/sync-to-flights-front.sh +++ b/scripts/sync-to-flights-front.sh @@ -1,142 +1,20 @@ #!/usr/bin/env bash +# sync-to-flights-front.sh — local dev convenience wrapper. +# +# Calls scripts/ci/sync-to-gitlab.sh with the local sibling-repo default. +# CI uses scripts/ci/sync-to-gitlab.sh directly with a fresh clone target. set -euo pipefail -# Sync the React app from this repo to the flights-front deployment repo. -# -# Usage: -# ./scripts/sync-to-flights-front.sh [target-dir] -# -# Default target: /Users/gnezim/_projects/tims/flights-front/Aeroflot.Flights.Front -# -# The deploy repo has the shape: -# flights-front/ -# Aeroflot.Flights.Front/ ← app source (target of this sync) -# deployment/ ← k8s manifests, ci scripts, etc. -# Anything under this repo's top-level deployment/ is copied to the -# sibling deployment/ in the deploy repo so cluster config lives with -# the source that consumes its env vars. - SRC_DIR="$(cd "$(dirname "$0")/.." && pwd)" TARGET_DIR="${1:-/Users/gnezim/_projects/tims/flights-front/Aeroflot.Flights.Front}" + +"$SRC_DIR/scripts/ci/sync-to-gitlab.sh" "$TARGET_DIR" + DEPLOY_ROOT="$(cd "$TARGET_DIR/.." && pwd)" -if [ ! -d "$TARGET_DIR" ]; then - echo "Error: target directory does not exist: $TARGET_DIR" - exit 1 -fi - -echo "Syncing: $SRC_DIR → $TARGET_DIR" -echo " $SRC_DIR/deployment → $DEPLOY_ROOT/deployment" -echo "" - -# ── Step 1: Clean target (preserve node_modules, .git, .dockerignore) ──────── - -echo "1/6 Cleaning target directory..." -find "$TARGET_DIR" -mindepth 1 -maxdepth 1 \ - ! -name "node_modules" \ - ! -name ".dockerignore" \ - -exec rm -rf {} + - -# ── Step 2: Copy source files ──────────────────────────────────────────────── - -echo "2/6 Copying source files..." - -# App source & config -cp -r "$SRC_DIR/src" "$TARGET_DIR/src" -cp -r "$SRC_DIR/tests" "$TARGET_DIR/tests" -cp -r "$SRC_DIR/scripts" "$TARGET_DIR/scripts" -# Modern.js publicDir — fonts, images, leaflet icons, favicons. Copied to -# dist/standalone/public/ at build time. Without these the app serves the -# SPA index for /assets/** and breaks @font-face, img references, tile icons. -cp -r "$SRC_DIR/config" "$TARGET_DIR/config" -cp "$SRC_DIR/package.json" "$TARGET_DIR/package.json" -cp "$SRC_DIR/pnpm-lock.yaml" "$TARGET_DIR/pnpm-lock.yaml" -cp "$SRC_DIR/tsconfig.json" "$TARGET_DIR/tsconfig.json" -cp "$SRC_DIR/modern.config.ts" "$TARGET_DIR/modern.config.ts" -cp "$SRC_DIR/module-federation.config.ts" "$TARGET_DIR/module-federation.config.ts" -cp "$SRC_DIR/vitest.config.ts" "$TARGET_DIR/vitest.config.ts" -cp "$SRC_DIR/playwright.config.ts" "$TARGET_DIR/playwright.config.ts" -cp "$SRC_DIR/eslint.config.js" "$TARGET_DIR/eslint.config.js" -cp "$SRC_DIR/Makefile" "$TARGET_DIR/Makefile" -cp "$SRC_DIR/CLAUDE.md" "$TARGET_DIR/CLAUDE.md" -cp "$SRC_DIR/AGENTS.md" "$TARGET_DIR/AGENTS.md" - -# Dockerfile — use the SSR-specific one -cp "$SRC_DIR/Dockerfile.react" "$TARGET_DIR/Dockerfile" - -# ── Step 3: Copy deployment configs to the sibling deployment/ dir ────────── - -echo "3/6 Copying deployment configs..." - -if [ -d "$SRC_DIR/deployment" ]; then - mkdir -p "$DEPLOY_ROOT/deployment" - # Mirror deployment/ without nuking unrelated files under the deploy - # repo's deployment dir — copy contents, don't wipe the target. - cp -R "$SRC_DIR/deployment/." "$DEPLOY_ROOT/deployment/" - echo " copied $(find "$SRC_DIR/deployment" -type f | wc -l | tr -d ' ') file(s) into $DEPLOY_ROOT/deployment" -else - echo " (no deployment/ dir in source repo — skipping)" -fi - -# ── Step 4: Clean up artifacts that shouldn't be in the target ──────────────── - -echo "4/6 Cleaning up artifacts..." - -# Remove debug screenshots -find "$TARGET_DIR" -maxdepth 1 -name "*.png" -delete 2>/dev/null || true - -# Remove Angular-specific files that may have leaked -rm -rf "$TARGET_DIR/src/server/middleware/"*.test.ts 2>/dev/null || true - -# Remove this sync script from the target (it's only needed in the source repo) -rm -f "$TARGET_DIR/scripts/sync-to-flights-front.sh" 2>/dev/null || true - -# Remove dev-server proxy script (flights-front has its own deployment) -# Keep it — it's useful for local dev - -# Remove Angular comparison scripts -rm -rf "$TARGET_DIR/scripts/phase-0" 2>/dev/null || true -rm -f "$TARGET_DIR/scripts/screenshot-diff.ts" 2>/dev/null || true - -# Remove playwright-angular config if copied -rm -f "$TARGET_DIR/playwright-angular.config.ts" 2>/dev/null || true - -# Remove test files that reference Angular -rm -rf "$TARGET_DIR/tests/e2e-angular" 2>/dev/null || true -rm -rf "$TARGET_DIR/tests/parity" 2>/dev/null || true - -# ── Step 5: Ensure .dockerignore exists ────────────────────────────────────── - -echo "5/6 Ensuring .dockerignore..." - -if [ ! -f "$TARGET_DIR/.dockerignore" ]; then - cat > "$TARGET_DIR/.dockerignore" << 'DOCKERIGNORE' -node_modules -dist -coverage -test-results -playwright-report -.playwright-mcp -*.png -*.md -.git -.claude -.gstack -DOCKERIGNORE -fi - -# ── Step 6: Summary ───────────────────────────────────────────────────────── - -echo "6/6 Done!" -echo "" -echo "Synced app files:" -ls -1 "$TARGET_DIR" | grep -v node_modules -if [ -d "$DEPLOY_ROOT/deployment" ]; then - echo "" - echo "Synced deployment files:" - (cd "$DEPLOY_ROOT" && find deployment -type f | sort) -fi -echo "" +echo +echo "Synced app files at $TARGET_DIR" +echo echo "Next steps:" echo " cd $TARGET_DIR" echo " pnpm install # if lock file changed"