.DEFAULT_GOAL := help
.PHONY: *
theme := proudnerds

install: install-git-hooks clean composer-dev assets build ## Clean the vendor directory, run composer install, build the theme
prod: composer assets build cleanup ## Build for production - don't run this locally!

install-git-hooks: ## Install git hooks from private/git-hooks
	@echo "Installing git hooks from private/git-hooks/ folder to .git/hooks/"
	@test -d ./.git/hooks || mkdir ./.git/hooks
	@cp ./private/git-hooks/* ./.git/hooks/
	@find ./.git/hooks/ -type f ! -name "*.sample" -exec chmod +x {} \;

docs: ## Use phpdoc (@see Docker LEMP environment documentation) to update documentation
	@echo "Running phpdoc to install documentation"
	@docker run --rm -v ${PWD}:/data phpdoc/phpdoc

pre-commit: ## run pre-commit hooks
	@echo "Running pre-commit hooks"
	@.git/hooks/pre-commit

clean: ## Clean the vendor directory and the node modules
	@echo "Cleaning vendor and node_modules directories"
	@rm -rf public/vendor public/content/themes/${theme}/node_modules

composer-dev: ## Run composer install with dev dependencies
	@echo "Running composer install with dev dependencies"
	@composer install --prefer-source

composer:
	@echo "Running: composer install without dev dependencies"
	@composer install --prefer-dist --no-dev

assets: ## compile the theme
#	Make svg dir
	@echo "Creating: icons folder"
	@mkdir -p ./public/content/themes/${theme}/assets/icons/svg
	@echo "Executing: yarn install"
	@cd ./public/content/themes/${theme}/ && yarn

icons: ## Build the icons
	@echo "Building: icon fonts"
	@cd ./public/content/themes/${theme}/ && yarn icons

build: ## Build the theme assets
	@echo "Executing: yarn build"
	@cd ./public/content/themes/${theme}/ && yarn build

cleanup: ## Cleanup for production
ifndef ALLOW_PRODUCTION_BUILD
	@echo "You need to set the environment variable 'ALLOW_PRODUCTION_BUILD' to 'true' to run this command"
	@exit 1
endif
	@echo "Cleaning up for production environment"
	@rm -rf .git .gitignore composer.json composer.lock Makefile README.md .prettierrc .idehelper.php .php-cs-fixer.php bitbucket-pipelines.yml phpdoc.xml docs private public/fallback.php .vscode auth.json
	@cd ./public/content/themes/${theme}/ && rm -rf node_modules .fantasticonrc.js composer.json composer.lock package.json postcss.config.js vite.config.js yarn.lock

update:
	@echo "Running composer update"
	composer update

dev: ## Run Vite with live reload
	@echo "Running development environment"
	@cd ./public/content/themes/${theme}/ && yarn dev

watch: ## Run Vite with watch mode (to be used in backend)
	@echo "Running development environment"
	@cd ./public/content/themes/${theme}/ && yarn build --watch

help:
	@printf "\033[33mUsage:\033[0m\n  make [target] \n\n\033[33mTargets:\033[0m\n"
	@grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
