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

install: clean setup build ## Clean the vendor directory, run composer install, build the theme
prod: install cleanup ## Build for production

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

setup: ## Run composer install and compile the theme
	@echo "Installing Composer packages"
	composer install
#	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
	@echo "Cleaning up for production environment"
	@rm -rf .git .gitignore composer.json composer.lock Makefile README.md
	@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/'