-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
69 lines (57 loc) · 1.89 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
.DEFAULT_GOAL := help
MAKE_PARAMS := $(filter-out $@,$(MAKECMDGOALS))
FILE_PATH := $(word 2,$(MAKE_PARAMS))
.PHONY: help
help: ## This help menu
@grep -E '^\S+:.*?## .*$$' $(firstword $(MAKEFILE_LIST)) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "%-30s %s\n", $$1, $$2}'
.PHONY: compile
compile: ## Compile binary
@go build -o optimize
.PHONY: install
install: ## Local install
@go install github.com/EricDriussi/hugo-image-optimizer@latest
.PHONY: setup
setup: ## Setup dev env
@go install github.com/vektra/mockery/v2@latest
@go get
.PHONY: mocks
mocks: ## Create mocks
@mockery -r --case=snake --outpkg=mocks --output=test/mocks --name=PostRepository
@mockery -r --case=snake --outpkg=mocks --output=test/mocks --name=ImageRepository
.PHONY: test
test: ## Run tests
ifdef FILE_PATH
@$(call COLOR_COMMAND, go test $(FILE_PATH))
else
@$(call COLOR_COMMAND, go test ./...)
endif
.PHONY: test-cover
test-cover: ## Test coverage report
@go test ./... -coverprofile=cover.html
@go tool cover -html=cover.html
@rm cover.html
.PHONY: test-watch
test-watch: ## Run tests in watch mode
ifdef FILE_PATH
@$(call COLOR_COMMAND, go test $(FILE_PATH))
@while true; do \
inotifywait -qq -r -e create,modify,move,delete ./; \
printf "\n[ . . . Re-running command . . . ]\n"; \
$(call COLOR_COMMAND, go test $(FILE_PATH)); \
done
else
@$(call COLOR_COMMAND, go test ./...)
@while true; do \
inotifywait -qq -r -e create,modify,move,delete ./; \
printf "\n[ . . . Re-running command . . . ]\n"; \
$(call COLOR_COMMAND, go test ./...); \
done
endif
# Color Command
PASS_COLOR=$(shell echo -e "\e[1;32m")
FAIL_COLOR=$(shell echo -e "\e[1;31m")
RESET_COLOR=$(shell echo -e "\e[0m")
COLORED_PASS_TERMS=✅ $(PASS_COLOR)&$(RESET_COLOR)
COLORED_FAIL_TERMS=❌ $(FAIL_COLOR)&$(RESET_COLOR)
COLOR_COMMAND = $(1) | sed -Ee "s/\<pass\>|\<ok\>/$(COLORED_PASS_TERMS)/I" -Ee "s/\<fail\>|\<failed\>/$(COLORED_FAIL_TERMS)/I"