-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
447 lines (356 loc) · 11.6 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
#---VARIABLES---------------------------------#
ifndef ROOT
ROOT:= $(shell ( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P ))
GENERATE_DATA= $(ROOT)/scriptGenerateDataApp.sh
endif
#---GIT---#
GIT = git
GIT_SUBMODULE = $(GIT) submodule
GIT_SUBMODULE_UPDATE = $(GIT_SUBMODULE) update --init
GIT_SUBMODULE_FOREACH = $(GIT_SUBMODULE) foreach
#------------#
#---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--#
# Determine if the Symfony binary exists
ifeq (, $(shell which symfony))
SYMFONY_BIN = php bin/console
SYMFONY_SERVER_START = php -S localhost:8000 -t public > var/log/server.log 2>&1 &
SYMFONY_SERVER_STOP = kill `lsof -t -i:8000`
SYMFONY = $(SYMFONY_BIN)
SYMFONY_CONSOLE = $(SYMFONY_BIN)
else
SYMFONY_BIN = symfony
SYMFONY_SERVER_START = $(SYMFONY_BIN) serve -d
SYMFONY_SERVER_STOP = $(SYMFONY_BIN) server:stop
SYMFONY = $(SYMFONY_BIN)
SYMFONY_CONSOLE = $(SYMFONY) console
endif
SYMFONY_LINT = $(SYMFONY_CONSOLE) lint:
#------------#
#---MODULE-#
SIMULATE = $(SYMFONY_CONSOLE) app:module:simulate
#------------#
#---COMPOSER-#
COMPOSER = composer
COMPOSER_INSTALL = $(COMPOSER) install
COMPOSER_UPDATE = $(COMPOSER) update
#------------#
#---PNPM-----#
PNPM = pnpm
PNPM_INSTALL = $(PNPM) install --force
PNPM_UPDATE = $(PNPM) update
PNPM_BUILD = $(PNPM) run build
PNPM_DEV = $(PNPM) run dev
PNPM_DEV_SERVER = $(PNPM) run dev-server
PNPM_WATCH = $(PNPM) run watch
#------------#
#---YARN-----#
YARN = yarn
YARN_INSTALL = $(YARN) install --force
YARN_UPDATE = $(YARN) update
YARN_BUILD = $(YARN) run build
YARN_DEV = $(YARN) run dev
YARN_DEV_SERVER = $(YARN) run dev-server
YARN_WATCH = $(YARN) run watch
#------------#
#---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: ## List and Use All Symfony commands (make sf command="commande-name").
$(SYMFONY_CONSOLE) $(command)
.PHONY: sf
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-assets: ## Install bundle's web assets under a public directory.
$(SYMFONY_CONSOLE) assets:install
.PHONY: sf-assets
sf-log: ## Show symfony logs.
$(SYMFONY) server:log
.PHONY: sf-log
sf-dc: ## Create symfony database.
$(SYMFONY_CONSOLE) doctrine:database:create --if-not-exists > /dev/null 2>&1 || true
$(SYMFONY_CONSOLE) doctrine:database:create > /dev/null 2>&1 || true # A hack to support both mysql and sqlite
.PHONY: sf-dc
sf-dd: ## Drop symfony database.
$(SYMFONY_CONSOLE) doctrine:database:drop --if-exists --force > /dev/null 2>&1 || true
$(SYMFONY_CONSOLE) doctrine:database:drop --force > /dev/null 2>&1 || true # A hack to support both mysql and sqlite
.PHONY: sf-dd
sf-su: ## Update symfony schema database.
$(SYMFONY_CONSOLE) doctrine:schema:update --force
.PHONY: sf-su
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) hautelook:fixtures:load --no-interaction
#$(SYMFONY_CONSOLE) doctrine:fixtures:load --no-interaction
.PHONY: sf-fixtures
sf-me: ## Make symfony entity
$(SYMFONY_CONSOLE) make:entity
.PHONY: sf-me
sf-mc: ## Make symfony controller
$(SYMFONY_CONSOLE) make:controller
.PHONY: sf-mc
sf-mf: ## Make symfony Form
$(SYMFONY_CONSOLE) make:form
.PHONY: sf-mf
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 project in a browser.
$(SYMFONY) open:local
.PHONY: sf-open
sf-open-email: ## Open Email catcher.
$(SYMFONY) open:local:webmail
.PHONY: sf-open-email
sf-check-requirements: ## Check requirements.
$(SYMFONY) check:requirements
.PHONY: sf-check-requirements
#---------------------------------------------#
## === 📦 COMPOSER ==============================================
composer-install: ## Install composer dependencies.
$(COMPOSER_INSTALL)
.PHONY: composer-install
composer: ## Alias of composer-install. Install composer dependencies.
$(COMPOSER_INSTALL)
.PHONY: composer
composer-update: ## Update composer dependencies.
$(COMPOSER_UPDATE)
.PHONY: composer-update
composer-validate: ## Validate composer.json file.
$(COMPOSER) validate
.PHONY: composer-validate
composer-validate-deep: ## Validate composer.json and composer.lock files in strict mode.
$(COMPOSER) validate --strict --check-lock
.PHONY: composer-validate-deep
#---------------------------------------------#
## === 📦 PNPM ===================================================
pnpm-install: ## Install pnpm dependencies.
pnpm install
.PHONY: pnpm-install
pnpm-update: ## Update pnpm dependencies.
pnpm update
.PHONY: pnpm-update
pnpm-build: ## Build assets.
pnpm run build
.PHONY: pnpm-build
pnpm-dev: ## Build assets in dev mode.
pnpm run dev
.PHONY: pnpm-dev
pnpm-dev-server: ## Build assets in dev mode and watch.
pnpm run dev-server
.PHONY: pnpm-dev-server
pnpm-watch: ## Watch assets.
pnpm run watch
.PHONY: pnpm-watch
#---------------------------------------------#
## === 📦 YARN ===================================================
yarn-install: ## Install yarn dependencies.
$(YARN_INSTALL)
.PHONY: yarn-install
yarn-update: ## Update yarn dependencies.
$(YARN_UPDATE)
.PHONY: yarn-update
yarn-build: ## Build assets.
$(YARN_BUILD)
.PHONY: yarn-build
yarn-dev: ## Build assets in dev mode.
$(YARN_DEV)
.PHONY: yarn-dev
yarn-dev-server: ## Build assets in dev mode and watch.
$(YARN_DEV_SERVER)
.PHONY: yarn-dev-server
yarn-watch: ## Watch assets.
$(YARN_WATCH)
.PHONY: yarn-watch
#---------------------------------------------#
# === 📦 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
qa-audit: ## Run composer audit.
$(COMPOSER) audit
.PHONY: qa-audit
#---------------------------------------------#
## === 🔎 TESTS =================================================
tests: ## Run tests.
$(PHPUNIT) --testdox
.PHONY: tests
tests-coverage: ## Run tests with coverage.
$(PHPUNIT) --coverage-html var/coverage
.PHONY: tests-coverage
#---------------------------------------------#
## === ⭐ APPLICATION =================================================
bundles: ## Generate fixtures from Bundles.
$(MAKE) sf-dd
$(MAKE) sf-dc
$(MAKE) sf-su
$(MAKE) sf-fixtures --append --group=bundles
.PHONY: bundles
pem: ## Generate JWT tokens.
mkdir -p config/jwt
openssl genrsa -out config/jwt/private.pem 4096
openssl rsa -pubout -in config/jwt/private.pem -out config/jwt/public.pem
chmod -R 775 config/
.PHONY: pem
data: ## Generate fixtures for the project.
$(MAKE) sf-dd
$(MAKE) sf-dc
$(MAKE) sf-su
$(MAKE) sf-fixtures
.PHONY: data
checkout: ## Pull all modules for the specified branch. Eg: make checkout dev
$(GIT) pull
$(GIT_SUBMODULE_UPDATE)
$(GIT_SUBMODULE_FOREACH) git fetch origin
$(GIT_SUBMODULE_FOREACH) git checkout $(filter-out $@,$(MAKECMDGOALS))
$(GIT_SUBMODULE_FOREACH) git pull
.PHONY: checkout
checkout-dev: ## Pull all modules for branch dev.
$(GIT) pull
$(GIT_SUBMODULE_UPDATE)
$(GIT_SUBMODULE_FOREACH) git checkout dev
$(GIT_SUBMODULE_FOREACH) git pull
.PHONY: checkout-dev
#---------------------------------------------#
## === MODULE SIMULATION =================================================
simulate: ## Run simulation.
$(SIMULATE)
.PHONY: simulate
#---------------------------------------------#
## === ⭐ OTHERS =================================================
before-commit: qa-cs-fixer qa-phpstan qa-security-checker qa-phpcpd qa-lint-twigs qa-lint-yaml qa-lint-container qa-lint-schema tests ## Run before commit.
.PHONY: before-commit
dev: docker-up yarn-build sf-perm data sf-start sf-open ## First install.
.PHONY: dev
first-install: ## First install.
$(MAKE) composer-install
$(MAKE) pnpm-install
$(MAKE) pnpm-build || true
$(MAKE) sf-perm || true
$(MAKE) pem
$(MAKE) data
$(MAKE) sf-cc || true
$(MAKE) sf-assets
$(MAKE) sf-start
$(MAKE) sf-open
.PHONY: first-install
start: docker-up sf-start sf-open ## Start project.
.PHONY: start
stop: docker-stop sf-stop ## Stop project.
.PHONY: stop
clear: ## Clear symfony cache.
$(sf-cc)
.PHONY: clear
reset-db: ## Reset database.
$(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-dmm; \
fi
.PHONY: reset-db
#---------------------------------------------#