diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..f50c214f --- /dev/null +++ b/Makefile @@ -0,0 +1,119 @@ +.PHONY: help dev dev-full stop status logs build build-remote build-both test test-coverage lint typecheck e2e check clean install sync + +help: + @echo "Aeroflot.Flights.Web — Available commands:" + @echo "" + @echo " Development:" + @echo " make dev - Start Modern.js dev server (:8081)" + @echo " make dev-full - Start dev server with API proxy (:8080)" + @echo " make stop - Stop running dev server" + @echo " make status - Check if dev server is running" + @echo " make logs - View dev server logs (tail -f)" + @echo "" + @echo " Building:" + @echo " make build - Build standalone SSR server" + @echo " make build-remote - Build MF remote (mf-manifest.json)" + @echo " make build-both - Build standalone + remote" + @echo " make clean - Clean build artifacts" + @echo "" + @echo " Testing & Quality:" + @echo " make test - Run unit tests (Vitest)" + @echo " make test-coverage - Run tests with coverage" + @echo " make lint - Lint code (ESLint)" + @echo " make typecheck - Type check (TypeScript)" + @echo " make check - Run typecheck + lint + test" + @echo "" + @echo " E2E Testing:" + @echo " make e2e - Run Playwright E2E tests" + @echo "" + @echo " Deployment:" + @echo " make sync - Sync files to flights-front repo" + @echo "" + @echo " Setup:" + @echo " make install - Install dependencies (pnpm install)" + +PNPM := pnpm +PID_FILE := .dev.pid +LOG_FILE := .dev.log + +# Development +dev: + @echo "Starting Modern.js dev server in background..." + @nohup $(PNPM) dev > $(LOG_FILE) 2>&1 & echo $$! > $(PID_FILE) + @echo "Dev server started (PID: $$(cat $(PID_FILE)))" + @echo "View logs: make logs" + +dev-full: + @echo "Starting dev server with API proxy in background..." + @nohup $(PNPM) dev:full > $(LOG_FILE) 2>&1 & echo $$! > $(PID_FILE) + @echo "Dev server started (PID: $$(cat $(PID_FILE)))" + @echo " App: http://localhost:8080" + @echo " API: http://localhost:8080/api/*" + @echo "View logs: make logs" + +stop: + @echo "Stopping dev server..." + @if [ -f $(PID_FILE) ]; then \ + kill $$(cat $(PID_FILE)) 2>/dev/null || true; \ + rm -f $(PID_FILE); \ + fi + @pkill -f "modern dev" 2>/dev/null || true + @pkill -f "node scripts/dev-server" 2>/dev/null || true + @lsof -ti:8080 -ti:8081 2>/dev/null | xargs kill 2>/dev/null || true + @echo "Stopped" + +status: + @if [ -f $(PID_FILE) ] && ps -p $$(cat $(PID_FILE)) > /dev/null 2>&1; then \ + echo "Dev server is running (PID: $$(cat $(PID_FILE)))"; \ + else \ + rm -f $(PID_FILE) 2>/dev/null; \ + echo "Dev server is not running"; \ + fi + +logs: + @if [ -f $(LOG_FILE) ]; then \ + tail -f $(LOG_FILE); \ + else \ + echo "No log file. Start server with: make dev"; \ + fi + +# Building +build: + $(PNPM) build:standalone + +build-remote: + $(PNPM) build:remote + +build-both: + $(PNPM) build:both + +clean: + rm -rf dist/ + @echo "Clean complete" + +# Testing & Quality +test: + $(PNPM) test + +test-coverage: + $(PNPM) test:coverage + +lint: + $(PNPM) lint + +typecheck: + $(PNPM) typecheck + +check: typecheck lint test + +# E2E +e2e: + $(PNPM) test:e2e + +# Deployment +sync: + ./scripts/sync-to-flights-front.sh + +# Setup +install: + $(PNPM) install diff --git a/scripts/sync-to-flights-front.sh b/scripts/sync-to-flights-front.sh new file mode 100755 index 00000000..cbdd91cc --- /dev/null +++ b/scripts/sync-to-flights-front.sh @@ -0,0 +1,110 @@ +#!/usr/bin/env bash +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 + +SRC_DIR="$(cd "$(dirname "$0")/.." && pwd)" +TARGET_DIR="${1:-/Users/gnezim/_projects/tims/flights-front/Aeroflot.Flights.Front}" + +if [ ! -d "$TARGET_DIR" ]; then + echo "Error: target directory does not exist: $TARGET_DIR" + exit 1 +fi + +echo "Syncing: $SRC_DIR → $TARGET_DIR" +echo "" + +# ── Step 1: Clean target (preserve node_modules, .git, .dockerignore) ──────── + +echo "1/5 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/5 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" +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" + +# Dockerfile — use the SSR-specific one +cp "$SRC_DIR/Dockerfile.react" "$TARGET_DIR/Dockerfile" + +# ── Step 3: Clean up artifacts that shouldn't be in the target ──────────────── + +echo "3/5 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 4: Ensure .dockerignore exists ────────────────────────────────────── + +echo "4/5 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 5: Summary ───────────────────────────────────────────────────────── + +echo "5/5 Done!" +echo "" +echo "Synced files:" +ls -1 "$TARGET_DIR" | grep -v node_modules +echo "" +echo "Next steps:" +echo " cd $TARGET_DIR" +echo " pnpm install # if lock file changed" +echo " make check # typecheck + lint + test" +echo " git diff # review changes"