# Makefile for Inkscape MCP Extension

# Variables
PYTHON := python3
SRC_DIR := src
DIST_DIR := dist
BUILD_SCRIPT := build.py
EXTENSION_NAME := inkscape-tools

# Default target
.PHONY: all
all: build

# Build the extension
.PHONY: build
build:
	@echo "🔨 Building Inkscape MCP Extension..."
	$(PYTHON) $(BUILD_SCRIPT) --src $(SRC_DIR) --output $(DIST_DIR)

# Build with verbose output
.PHONY: build-verbose
build-verbose:
	@echo "🔨 Building Inkscape MCP Extension (verbose)..."
	$(PYTHON) $(BUILD_SCRIPT) --src $(SRC_DIR) --output $(DIST_DIR) --verbose

# Build without dependencies (for development)
.PHONY: build-no-deps
build-no-deps:
	@echo "🔨 Building Inkscape MCP Extension (no dependencies)..."
	$(PYTHON) $(BUILD_SCRIPT) --src $(SRC_DIR) --output $(DIST_DIR) --no-deps

# Clean build artifacts
.PHONY: clean
clean:
	@echo "🧹 Cleaning build artifacts..."
	rm -rf $(DIST_DIR)
	rm -rf src/server/__pycache__
	rm -rf src/server/utils/__pycache__
	find . -name "*.pyc" -delete
	find . -name "*.pyo" -delete
	find . -name "__pycache__" -type d -exec rm -rf {} +

# Install dependencies for development
.PHONY: install-deps
install-deps:
	@echo "📦 Installing development dependencies..."
	$(PYTHON) -m pip install -r src/server/requirements.txt

# Run tests
.PHONY: test
test:
	@echo "🧪 Running tests..."
	$(PYTHON) -m pytest tests/ -v

# Lint the code
.PHONY: lint
lint:
	@echo "🔍 Linting code..."
	$(PYTHON) -m flake8 src/server/ --max-line-length=100
	$(PYTHON) -m black --check src/server/

# Format the code
.PHONY: format
format:
	@echo "✨ Formatting code..."
	$(PYTHON) -m black src/server/

# Validate the manifest
.PHONY: validate
validate:
	@echo "✅ Validating manifest..."
	$(PYTHON) -c "import json; json.load(open('$(SRC_DIR)/manifest.json')); print('Manifest is valid JSON')"

# Create a development build and test it
.PHONY: dev-build
dev-build: clean build
	@echo "🚀 Development build complete!"
	@echo "📁 Extension file: $(shell ls -1 $(DIST_DIR)/*.dxt | head -1)"

# Package for release
.PHONY: release
release: clean validate build
	@echo "🎉 Release build complete!"
	@echo "📦 Ready for distribution: $(shell ls -1 $(DIST_DIR)/*.dxt | head -1)"

# Show help
.PHONY: help
help:
	@echo "Inkscape MCP Extension Build System"
	@echo ""
	@echo "Available targets:"
	@echo "  build          - Build the extension (.dxt file)"
	@echo "  build-verbose  - Build with verbose output"
	@echo "  build-no-deps  - Build without installing dependencies"
	@echo "  clean          - Remove build artifacts"
	@echo "  install-deps   - Install development dependencies"
	@echo "  test           - Run tests"
	@echo "  lint           - Lint the code"
	@echo "  format         - Format the code"
	@echo "  validate       - Validate manifest.json"
	@echo "  dev-build      - Clean build for development"
	@echo "  release        - Clean build for release"
	@echo "  help           - Show this help message"
