# ==================================
# Riichi Mahjong Tutorial - Makefile
# ==================================

.PHONY: all dev build preview test lint format clean hard-clean zip help install

# Default target
all: build

# Install dependencies
install:
	@echo "Installing dependencies..."
	npm install

# Development server with hot reload
dev:
	@echo "Starting development server..."
	npm run dev

# Production build
build:
	@echo "Building for production..."
	npm run build

# Preview production build
preview:
	@echo "Previewing production build..."
	npm run preview

# Run tests
test:
	@echo "Running tests..."
	npm run test

# Run tests in watch mode
test-watch:
	@echo "Running tests in watch mode..."
	npm run test:watch

# Lint code
lint:
	@echo "Linting code..."
	npm run lint

# Fix linting issues
lint-fix:
	@echo "Fixing linting issues..."
	npm run lint:fix

# Format code
format:
	@echo "Formatting code..."
	npm run format

# Type check
typecheck:
	@echo "Type checking..."
	npm run typecheck

# Create distribution zip
zip: build
	@echo "Creating distribution archive..."
	@rm -rf riichi
	@mkdir riichi
	@cp -r build riichi/
	@cp index.html riichi/
	@cp -r img riichi/
	@cp -r src/styles riichi/src/ 2>/dev/null || mkdir -p riichi/src && cp -r src/styles riichi/src/
	@zip -r riichi.zip riichi
	@rm -rf riichi
	@echo "Created riichi.zip"
# Clean build artifacts
clean:
	@echo "Cleaning build artifacts..."
	@rm -rf build/
	@rm -rf dist/
	@rm -f riichi.zip
	@rm -rf riichi/

# Deep clean (including dependencies)
hard-clean: clean
	@echo "Deep cleaning (including dependencies)..."
	@rm -rf node_modules/
	@rm -f package-lock.json
	@rm -rf .cache/
	@rm -f *.tsbuildinfo

# Show help
help:
	@echo ""
	@echo "Riichi Mahjong Tutorial - Available Commands"
	@echo "================================================"
	@echo ""
	@echo "  make install      - Install npm dependencies"
	@echo "  make dev          - Start development server with hot reload"
	@echo "  make build        - Build for production"
	@echo "  make preview      - Preview production build"
	@echo "  make test         - Run tests"
	@echo "  make test-watch   - Run tests in watch mode"
	@echo "  make lint         - Check code for linting errors"
	@echo "  make lint-fix     - Fix linting errors automatically"
	@echo "  make format       - Format code with Prettier"
	@echo "  make typecheck    - Run TypeScript type checking"
	@echo "  make zip          - Create distribution archive"
	@echo "  make clean        - Remove build artifacts"
	@echo "  make hard-clean   - Remove all generated files and dependencies"
	@echo ""
