-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
265 lines (216 loc) Β· 6.67 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#---Symfony-And-Docker-Makefile---------------#
# Author: https://github.com/yoanbernabeu
# License: MIT
#---------------------------------------------#
#---VARIABLES---------------------------------#
#---DOCKER---#
DOCKER = docker
DOCKER_RUN = $(DOCKER) run
DOCKER_COMPOSE = docker compose
DOCKER_COMPOSE_UP = $(DOCKER_COMPOSE) up -d
DOCKER_COMPOSE_STOP = $(DOCKER_COMPOSE) stop
#------------#
#---SYMFONY--#
SYMFONY = symfony
SYMFONY_SERVER_START = $(SYMFONY) serve -d
SYMFONY_SERVER_STOP = $(SYMFONY) server:stop
SYMFONY_CONSOLE = $(SYMFONY) console
SYMFONY_LINT = $(SYMFONY_CONSOLE) lint:
#------------#
#---COMPOSER-#
COMPOSER = composer
COMPOSER_INSTALL = $(COMPOSER) install
COMPOSER_UPDATE = $(COMPOSER) update
#------------#
#---NPM-----#
NPM = npm
NPM_INSTALL = $(NPM) install --force
NPM_UPDATE = $(NPM) update
NPM_BUILD = $(NPM) run build
NPM_DEV = $(NPM) run dev
NPM_WATCH = $(NPM) run watch
#------------#
#---PHPQA---#
PHPQA = jakzal/phpqa
PHPQA_RUN = $(DOCKER_RUN) --init -it --rm -v $(PWD):/project -w /project $(PHPQA)
#------------#
#---PHPUNIT-#
PHPUNIT = APP_ENV=test $(SYMFONY) php bin/phpunit
#------------#
#---------------------------------------------#
## === π HELP ==================================================
help: ## Show this help.
@echo "Symfony-And-Docker-Makefile"
@echo "---------------------------"
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@grep -E '(^[a-zA-Z0-9_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
#---------------------------------------------#
## === π DOCKER ================================================
docker-up: ## Start docker containers.
$(DOCKER_COMPOSE_UP)
.PHONY: docker-up
docker-stop: ## Stop docker containers.
$(DOCKER_COMPOSE_STOP)
.PHONY: docker-stop
#---------------------------------------------#
## === ποΈ SYMFONY ===============================================
sf-start: ## Start symfony server.
$(SYMFONY_SERVER_START)
.PHONY: sf-start
sf-stop: ## Stop symfony server.
$(SYMFONY_SERVER_STOP)
.PHONY: sf-stop
sf-cc: ## Clear symfony cache.
$(SYMFONY_CONSOLE) cache:clear
.PHONY: sf-cc
sf-log: ## Show symfony logs.
$(SYMFONY) server:log
.PHONY: sf-log
sf-dc: ## Create symfony database.
$(SYMFONY_CONSOLE) doctrine:database:create
.PHONY: sf-dc
sf-dd: ## Drop symfony database.
$(SYMFONY_CONSOLE) doctrine:database:drop --force
.PHONY: sf-dd
sf-mm: ## Make migrations.
$(SYMFONY_CONSOLE) make:migration
.PHONY: sf-mm
sf-dmm: ## Migrate.
$(SYMFONY_CONSOLE) doctrine:migrations:migrate --no-interaction
.PHONY: sf-dmm
sf-fixtures: ## Load fixtures.
$(SYMFONY_CONSOLE) doctrine:fixtures:load --no-interaction
.PHONY: sf-fixtures
sf-perm: ## Fix permissions.
chmod -R 777 var
.PHONY: sf-perm
sf-sudo-perm: ## Fix permissions with sudo.
sudo chmod -R 777 var
.PHONY: sf-sudo-perm
sf-dump-env: ## Dump env.
$(SYMFONY_CONSOLE) debug:dotenv
.PHONY: sf-dump-env
sf-dump-env-container: ## Dump Env container.
$(SYMFONY_CONSOLE) debug:container --env-vars
.PHONY: sf-dump-env-container
sf-dump-routes: ## Dump routes.
$(SYMFONY_CONSOLE) debug:router
.PHONY: sf-dump-routes
sf-open: ## Open symfony server.
$(SYMFONY) open:local
.PHONY: sf-open
sf-check-requirements: ## Check requirements.
$(SYMFONY) check:requirements
.PHONY: sf-check-requirements
#---------------------------------------------#
## === π¦ COMPOSER ==============================================
composer-install: ## Install composer dependencies.
$(COMPOSER_INSTALL)
.PHONY: composer-install
composer-update: ## Update composer dependencies.
$(COMPOSER_UPDATE)
.PHONY: composer-update
#---------------------------------------------#
## === π¦ NPM ===================================================
npm-install: ## Install npm dependencies.
$(NPM_INSTALL)
.PHONY: npm-install
npm-update: ## Update npm dependencies.
$(NPM_UPDATE)
.PHONY: npm-update
npm-build: ## Build assets.
$(NPM_BUILD)
.PHONY: npm-build
npm-dev: ## Build assets in dev mode.
$(NPM_DEV)
.PHONY: npm-dev
npm-watch: ## Watch assets.
$(NPM_WATCH)
.PHONY: npm-watch
#---------------------------------------------#
## === π PHPQA =================================================
qa-cs-fixer-dry-run: ## Run php-cs-fixer in dry-run mode.
$(PHPQA_RUN) php-cs-fixer fix ./src --rules=@Symfony --verbose --dry-run
.PHONY: qa-cs-fixer-dry-run
qa-cs-fixer: ## Run php-cs-fixer.
$(PHPQA_RUN) php-cs-fixer fix ./src --rules=@Symfony --verbose
.PHONY: qa-cs-fixer
qa-phpstan: ## Run phpstan.
$(PHPQA_RUN) phpstan analyse ./src --level=7
.PHONY: qa-phpstan
qa-security-checker: ## Run security-checker.
$(SYMFONY) security:check
.PHONY: qa-security-checker
qa-phpcpd: ## Run phpcpd (copy/paste detector).
$(PHPQA_RUN) phpcpd ./src
.PHONY: qa-phpcpd
qa-php-metrics: ## Run php-metrics.
$(PHPQA_RUN) phpmetrics --report-html=var/phpmetrics ./src
.PHONY: qa-php-metrics
qa-lint-twigs: ## Lint twig files.
$(SYMFONY_LINT)twig ./templates
.PHONY: qa-lint-twigs
qa-lint-yaml: ## Lint yaml files.
$(SYMFONY_LINT)yaml ./config
.PHONY: qa-lint-yaml
qa-lint-container: ## Lint container.
$(SYMFONY_LINT)container
.PHONY: qa-lint-container
qa-lint-schema: ## Lint Doctrine schema.
$(SYMFONY_CONSOLE) doctrine:schema:validate --skip-sync -vvv --no-interaction
.PHONY: qa-lint-schema
#---------------------------------------------#
## === π TESTS =================================================
tests: ## Run tests.
$(PHPUNIT) --testdox
.PHONY: tests
tests-coverage: ## Run tests with coverage.
$(PHPUNIT) --coverage-html var/coverage
.PHONY: tests-coverage
#---------------------------------------------#
## === β OTHER =================================================
before-commit: ## Run before commit.
$(MAKE) qa-cs-fixer
$(MAKE) qa-phpstan
$(MAKE) qa-security-checker
$(MAKE) qa-phpcpd
$(MAKE) qa-lint-twigs
$(MAKE) qa-lint-yaml
$(MAKE) qa-lint-container
$(MAKE) qa-lint-schema
$(MAKE) tests
.PHONY: before-commit
first-install: ## First install.
$(MAKE) docker-up
$(MAKE) composer-install
$(MAKE) npm-install
$(MAKE) npm-build
$(MAKE) sf-perm
$(MAKE) sf-dc
$(MAKE) sf-dmm
$(MAKE) sf-start
$(MAKE) sf-open
.PHONY: first-install
start: ## Start project.
$(MAKE) docker-up
$(MAKE) sf-start
$(MAKE) sf-open
.PHONY: start
stop: ## Stop project.
$(MAKE) docker-stop
$(MAKE) sf-stop
.PHONY: stop
reset-db: ## Reset database.
rm -f migrations/Version*.php
$(eval CONFIRM := $(shell read -p "Are you sure you want to reset the database? [y/N] " CONFIRM && echo $${CONFIRM:-N}))
@if [ "$(CONFIRM)" = "y" ]; then \
$(MAKE) sf-dd; \
$(MAKE) sf-dc; \
$(MAKE) sf-mm; \
$(MAKE) sf-dmm; \
$(MAKE) sf-fixtures; \
fi
.PHONY: reset-db
#---------------------------------------------#