.DEFAULT_GOAL := help

.PHONY: help install compile watch lint test package clean install-extension

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

install: ## Install development dependencies using pnpm
	pnpm install

compile: ## Compile the extension in development mode
	pnpm run compile

watch: ## Run the compiler in watch mode to automatically rebuild on file modifications
	pnpm run watch

lint: ## Run ESLint checks on TypeScript source code
	pnpm run lint

test: ## Execute the Jest test suite
	pnpm test

package: ## Package the extension into a local .vsix file for distribution
	pnpm run package

install-extension: ## Install the packaged .vsix file into your local VS Code instance
	@VSIX_FILE=$$(ls laravel-maestro-*.vsix 2>/dev/null | sort -V | tail -n 1); \
	if [ -n "$$VSIX_FILE" ]; then \
		echo "Installing $$VSIX_FILE..."; \
		code --install-extension "$$VSIX_FILE"; \
	else \
		echo "Error: No packaged .vsix file found. Run 'make package' first."; \
		exit 1; \
	fi

clean: ## Clean build artifacts (dist directory and .vsix packages)
	rm -rf dist
	rm -f *.vsix
