.PHONY: install dev setup lint format typecheck test check clean build publish

setup:  ## Install dependencies (dev environment)
	uv sync --all-groups

install:  ## Install libra globally as a CLI tool
	uv tool install --force -e .

uninstall:  ## Remove globally installed libra
	uv tool uninstall libra-ebook

lint:  ## Run linter
	uv run ruff check src/ tests/

format:  ## Format code
	uv run ruff format src/ tests/

typecheck:  ## Run type checker
	uv run mypy src/libra/

test:  ## Run tests
	uv run pytest tests/ -v

check: lint typecheck test  ## Run all checks (lint + typecheck + test)

clean:  ## Remove build artifacts
	rm -rf dist/ build/ *.egg-info src/*.egg-info .pytest_cache .mypy_cache .ruff_cache

build: clean  ## Build distribution packages
	uv build

publish: build  ## Publish to PyPI (reads token from ~/.pypirc)
	uv publish --token "$$(awk '/password/{print $$3}' ~/.pypirc)"

help:  ## Show this help
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
		awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'

.DEFAULT_GOAL := help
