generated from wayofdev/laravel-package-tpl
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
203 lines (159 loc) · 5.92 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
-include .env
# BuildKit enables higher performance docker builds and caching possibility
# to decrease build times and increase productivity for free.
# https://docs.docker.com/compose/environment-variables/envvars/
export DOCKER_BUILDKIT ?= 1
# Binary to use, when executing docker-compose tasks
DOCKER_COMPOSE ?= docker compose
# Support image with all needed binaries, like envsubst, mkcert, wait4x
SUPPORT_IMAGE ?= wayofdev/build-deps:alpine-latest
APP_RUNNER ?= $(DOCKER_COMPOSE) run --rm --no-deps app
APP_COMPOSER ?= $(APP_RUNNER) composer
BUILDER_PARAMS ?= docker run --rm -i \
--env-file ./.env \
--env COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) \
--env COMPOSER_AUTH="$(COMPOSER_AUTH)"
BUILDER ?= $(BUILDER_PARAMS) $(SUPPORT_IMAGE)
BUILDER_WIRED ?= $(BUILDER_PARAMS) --network project.$(COMPOSE_PROJECT_NAME) $(SUPPORT_IMAGE)
# Shorthand envsubst command, executed through build-deps
ENVSUBST ?= $(BUILDER) envsubst
NPM_RUNNER ?= pnpm
# https://phpstan.org/user-guide/output-format
export PHPSTAN_OUTPUT_FORMAT ?= table
EXPORT_VARS = '\
$${COMPOSE_PROJECT_NAME} \
$${COMPOSER_AUTH}'
# Self documenting Makefile code
# ------------------------------------------------------------------------------------
ifneq ($(TERM),)
BLACK := $(shell tput setaf 0)
RED := $(shell tput setaf 1)
GREEN := $(shell tput setaf 2)
YELLOW := $(shell tput setaf 3)
LIGHTPURPLE := $(shell tput setaf 4)
PURPLE := $(shell tput setaf 5)
BLUE := $(shell tput setaf 6)
WHITE := $(shell tput setaf 7)
RST := $(shell tput sgr0)
else
BLACK := ""
RED := ""
GREEN := ""
YELLOW := ""
LIGHTPURPLE := ""
PURPLE := ""
BLUE := ""
WHITE := ""
RST := ""
endif
MAKE_LOGFILE = /tmp/wayofdev-laravel-data-query-builder.log
MAKE_CMD_COLOR := $(BLUE)
default: all
help:
@echo 'Management commands for package:'
@echo 'Usage:'
@echo ' ${MAKE_CMD_COLOR}make${RST} Setups dependencies for fresh-project, like composer install, git hooks and others...'
@grep -E '^[a-zA-Z_0-9%-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " ${MAKE_CMD_COLOR}make %-21s${RST} %s\n", $$1, $$2}'
@echo
@echo ' 📑 Logs are stored in $(MAKE_LOGFILE)'
@echo
@echo ' 📦 Package laravel-data-query-builder (github.com/wayofdev/laravel-data-query-builder)'
@echo ' 🤠 Author Andrij Orlenko (github.com/lotyp)'
@echo ' 🏢 ${YELLOW}Org wayofdev (github.com/wayofdev)${RST}'
.PHONY: help
.EXPORT_ALL_VARIABLES:
# Default action
# Defines default command when `make` is executed without additional parameters
# ------------------------------------------------------------------------------------
all: install hooks
.PHONY: all
# System Actions
# ------------------------------------------------------------------------------------
env: ## Generate .env file from example, use `make env force=true`, to force re-create file
ifeq ($(FORCE),true)
@echo "${YELLOW}Force re-creating .env file from example...${RST}"
$(ENVSUBST) $(EXPORT_VARS) < ./.env.example > ./.env
else ifneq ("$(wildcard ./.env)","")
@echo ""
@echo "${YELLOW}The .env file already exists! Use FORCE=true to re-create.${RST}"
else
@echo "Creating .env file from example"
$(ENVSUBST) $(EXPORT_VARS) < ./.env.example > ./.env
endif
.PHONY: env
prepare:
mkdir -p .build/php-cs-fixer
.PHONY: prepare
# Docker Actions
# ------------------------------------------------------------------------------------
up: # Creates and starts containers, defined in docker-compose and override file
$(DOCKER_COMPOSE) up --remove-orphans -d
.PHONY: up
down: # Stops and removes containers of this project
$(DOCKER_COMPOSE) down --remove-orphans --volumes
.PHONY: down
restart: down up ## Runs down and up commands
.PHONY: restart
clean: ## Stops containers if required and removes from system
$(DOCKER_COMPOSE) rm --force --stop
.PHONY: clean
ps: ## List running project containers
$(DOCKER_COMPOSE) ps
.PHONY: ps
logs: ## Show project docker logs with follow up mode enabled
$(DOCKER_COMPOSE) logs -f
.PHONY: logs
pull: ## Pull and update docker images in this project
$(DOCKER_COMPOSE) pull
.PHONY: pull
ssh: ## Login inside running docker container
$(APP_RUNNER) sh
.PHONY: ssh
# Composer
# ------------------------------------------------------------------------------------
install: ## Installs composer dependencies
$(APP_COMPOSER) install
.PHONY: install
update: ## Updates composer dependencies by running composer update command
$(APP_COMPOSER) update
.PHONY: update
# Code Quality, Git, Linting, Testing
# ------------------------------------------------------------------------------------
hooks: ## Install git hooks from pre-commit-config
pre-commit install
pre-commit autoupdate
.PHONY: hooks
lint: lint-yaml lint-php lint-stan ## Runs all linting commands
.PHONY: lint
lint-yaml: ## Lints yaml files inside project
yamllint .
.PHONY: lint-yaml
lint-php: prepare ## Fixes code to follow coding standards using php-cs-fixer
$(APP_COMPOSER) cs:fix
.PHONY: lint-php
lint-diff: prepare ## Runs php-cs-fixer in dry-run mode and shows diff which will by applied
$(APP_COMPOSER) cs:diff
.PHONY: lint-diff
lint-stan: ## Runs phpstan – static analysis tool
$(APP_COMPOSER) stan
.PHONY: lint-stan
lint-stan-ci:
$(APP_COMPOSER) stan:ci
.PHONY: lint-stan-ci
test: ## Run project php-unit and pest tests
$(APP_COMPOSER) test
.PHONY: test
test-cc: ## Run project php-unit and pest tests in coverage mode and build report
$(APP_COMPOSER) test:cc
.PHONY: test-cc
# Documentation
# ------------------------------------------------------------------------------------
docs-deps-update: ## Check for outdated dependencies and automatically update them using pnpm
cd docs && $(NPM_RUNNER) run deps:update
.PHONY: docs-deps-update
docs-deps-install: ## Install dependencies for documentation using pnpm
cd docs && $(NPM_RUNNER) install
.PHONY: docs-deps-install
docs-up: ## Start documentation server
cd docs && $(NPM_RUNNER) dev
.PHONY: docs-up