|
| 1 | +SHELL := /bin/bash |
| 2 | + |
| 3 | +DOCKER ?= docker |
| 4 | +DOCKER_COMPOSE ?= $(DOCKER) compose $(shell test -f .env.local && echo '--env-file .env --env-file .env.local') |
| 5 | +export CONTAINER_USER ?= $(shell id -u):$(shell id -g) |
| 6 | + |
| 7 | +RUN ?= $(if $(INSIDE_DEVCONTAINER),,$(DOCKER_COMPOSE) run --rm php) |
| 8 | +COMPOSER ?= $(RUN) composer |
| 9 | + |
| 10 | +## |
| 11 | +## Project |
| 12 | +## ----- |
| 13 | + |
| 14 | +var: |
| 15 | + mkdir var |
| 16 | + |
| 17 | +vendor: composer.json $(wildcard composer.lock) |
| 18 | + @if [ -f vendor/.lowest ]; then $(MAKE) install-lowest; else $(MAKE) install-highest; fi |
| 19 | + |
| 20 | +i: install-highest |
| 21 | +install-highest: ## Install highest Composer dependencies |
| 22 | + $(COMPOSER) install |
| 23 | + @rm -f vendor/.lowest |
| 24 | + @touch vendor |
| 25 | +.PHONY: i install-highest |
| 26 | + |
| 27 | +install-lowest: ## Install lowest Composer dependencies |
| 28 | + $(COMPOSER) update --prefer-lowest --prefer-stable |
| 29 | + @touch vendor/.lowest |
| 30 | + @touch vendor |
| 31 | +.PHONY: install-lowest |
| 32 | + |
| 33 | +up: ## Docker compose up |
| 34 | + $(DOCKER_COMPOSE) up --remove-orphans --build --detach $(ARGS) |
| 35 | +.PHONY: up |
| 36 | + |
| 37 | +down: ## Docker compose down |
| 38 | + $(DOCKER_COMPOSE) down --remove-orphans $(ARGS) |
| 39 | +.PHONY: down |
| 40 | + |
| 41 | +dc: docker-compose |
| 42 | +docker-compose: ## Run docker compose command: `make dc CMD=start` |
| 43 | + $(DOCKER_COMPOSE) $(CMD) |
| 44 | +.PHONY: dc docker-compose |
| 45 | + |
| 46 | +c: composer |
| 47 | +composer: ## Run Composer command: `make c CMD=start` |
| 48 | + $(COMPOSER) $(CMD) |
| 49 | +.PHONY: c composer |
| 50 | + |
| 51 | +run: ## Run a command using the php container: `make run CMD='php --version'` |
| 52 | + $(RUN) $(CMD) |
| 53 | +.PHONY: run |
| 54 | + |
| 55 | +t: terminal |
| 56 | +terminal: var ## Start a terminal inside the php container |
| 57 | + @$(if $(INSIDE_CONTAINER),echo 'Already inside docker container.'; exit 1,) |
| 58 | + $(DOCKER_COMPOSE) run --rm $(ARGS) php bash |
| 59 | +.PHONY: t terminal |
| 60 | + |
| 61 | +rescaffold: |
| 62 | + $(DOCKER) run \ |
| 63 | + --volume .:/project \ |
| 64 | + --user $(CONTAINER_USER) \ |
| 65 | + --interactive --tty --rm \ |
| 66 | + --pull always \ |
| 67 | + ghcr.io/phpyh/scaffolder:latest \ |
| 68 | + --user-name-default '$(shell git config user.name 2>/dev/null || whoami 2>/dev/null)' \ |
| 69 | + --user-email-default '$(shell git config user.email 2>/dev/null)' \ |
| 70 | + --package-project-default '$(shell basename $$(pwd))' |
| 71 | + git add --all 2>/dev/null || true |
| 72 | +.PHONY: rescaffold |
| 73 | + |
| 74 | +## |
| 75 | +## Tools |
| 76 | +## ----- |
| 77 | + |
| 78 | +fixer: var ## Fix code style using PHP-CS-Fixer |
| 79 | + $(RUN) php-cs-fixer fix --diff --verbose $(ARGS) |
| 80 | +.PHONY: fixer |
| 81 | + |
| 82 | +fixer-check: var ## Check code style using PHP-CS-Fixer |
| 83 | + $(RUN) php-cs-fixer fix --diff --verbose --dry-run $(ARGS) |
| 84 | +.PHONY: fixer-check |
| 85 | + |
| 86 | +rector: var ## Fix code style using Rector |
| 87 | + $(RUN) rector process $(ARGS) |
| 88 | +.PHONY: rector |
| 89 | + |
| 90 | +rector-check: var ## Check code style using Rector |
| 91 | + $(RUN) rector process --dry-run $(ARGS) |
| 92 | +.PHONY: rector-check |
| 93 | + |
| 94 | +phpstan: var vendor ## Analyze code using PHPStan |
| 95 | + $(RUN) phpstan analyze --memory-limit=1G $(ARGS) |
| 96 | +.PHONY: phpstan |
| 97 | + |
| 98 | +test: var vendor up ## Run tests using PHPUnit |
| 99 | + $(RUN) vendor/bin/phpunit $(ARGS) |
| 100 | +.PHONY: test |
| 101 | + |
| 102 | +infect: var vendor up ## Run mutation tests using Infection |
| 103 | + $(RUN) infection --show-mutations $(ARGS) |
| 104 | +.PHONY: infect |
| 105 | + |
| 106 | +deps-analyze: vendor ## Analyze project dependencies using Composer dependency analyser |
| 107 | + $(RUN) composer-dependency-analyser $(ARGS) |
| 108 | +.PHONY: deps-analyze |
| 109 | + |
| 110 | +composer-validate: ## Validate composer.json |
| 111 | + $(COMPOSER) validate $(ARGS) |
| 112 | +.PHONY: composer-validate |
| 113 | + |
| 114 | +composer-normalize: ## Normalize composer.json |
| 115 | + $(COMPOSER) normalize --no-check-lock --no-update-lock --diff $(ARGS) |
| 116 | +.PHONY: composer-normalize |
| 117 | + |
| 118 | +composer-normalize-check: ## Check that composer.json is normalized |
| 119 | + $(COMPOSER) normalize --diff --dry-run $(ARGS) |
| 120 | +.PHONY: composer-normalize-check |
| 121 | + |
| 122 | +fix: fixer rector composer-normalize ## Run all fixing recipes |
| 123 | +.PHONY: fix |
| 124 | + |
| 125 | +check: fixer-check rector-check composer-validate composer-normalize-check deps-analyze phpstan test ## Run all project checks |
| 126 | +.PHONY: check |
| 127 | + |
| 128 | +# ----------------------- |
| 129 | + |
| 130 | +help: |
| 131 | + @awk ' \ |
| 132 | + BEGIN {RS=""; FS="\n"} \ |
| 133 | + function printCommand(line) { \ |
| 134 | + split(line, command, ":.*?## "); \ |
| 135 | + printf "\033[32m%-28s\033[0m %s\n", command[1], command[2]; \ |
| 136 | + } \ |
| 137 | + /^[0-9a-zA-Z_-]+: [0-9a-zA-Z_-]+\n[0-9a-zA-Z_-]+: .*?##.*$$/ { \ |
| 138 | + split($$1, alias, ": "); \ |
| 139 | + sub(alias[2] ":", alias[2] " (" alias[1] "):", $$2); \ |
| 140 | + printCommand($$2); \ |
| 141 | + next; \ |
| 142 | + } \ |
| 143 | + $$1 ~ /^[0-9a-zA-Z_-]+: .*?##/ { \ |
| 144 | + printCommand($$1); \ |
| 145 | + next; \ |
| 146 | + } \ |
| 147 | + /^##(\n##.*)+$$/ { \ |
| 148 | + gsub("## ?", "\033[33m", $$0); \ |
| 149 | + print $$0; \ |
| 150 | + next; \ |
| 151 | + } \ |
| 152 | + ' $(MAKEFILE_LIST) && printf "\033[0m" |
| 153 | +.PHONY: help |
| 154 | + |
| 155 | +.DEFAULT_GOAL := help |
0 commit comments