Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be829eb

Browse files
committed
refactor: enhance Makefile and add Taskfile
1 parent 4e34543 commit be829eb

File tree

2 files changed

+207
-64
lines changed

2 files changed

+207
-64
lines changed

Makefile

Lines changed: 80 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
1-
color_red := $(shell printf "\e[1;31m")
2-
color_green := $(shell printf "\e[1;32m")
3-
color_yellow := $(shell printf "\e[1;33m")
4-
color_blue := $(shell printf "\e[1;34m")
5-
color_magenta := $(shell printf "\e[1;35m")
6-
color_cyan := $(shell printf "\e[1;36m")
1+
# Colors
2+
color_green := $(shell printf "\e[32m") # Green color
73
color_reset := $(shell printf "\e[0m")
84

9-
EXAMPLES := \
10-
_examples/a-h-templ-single-toast \
11-
_examples/a-h-templ-multiple-toasts \
12-
_examples/custom-animations \
13-
_examples/custom-icons \
14-
_examples/theming \
15-
_examples/variants \
16-
_examples/go-html-template-single-toast \
17-
_examples/go-html-template-multiple-toasts
18-
195
# ==================================================================================== #
206
# HELPERS
217
# ==================================================================================== #
@@ -26,61 +12,91 @@ help: ## Print this help message
2612
@echo ""
2713
@echo "Available Actions:"
2814
@echo ""
29-
@awk -F ':|##' '/^[^\t].+?:.*?##/ {printf " \033[36m%-15s\033[0m %s\n", $$1, $$NF}' $(MAKEFILE_LIST) | sort
15+
@awk -v green="$(color_green)" -v reset="$(color_reset)" -F ':|##' \
16+
'/^[^\t].+?:.*?##/ {printf "%s* %-15s%s %s\n", green, $$1, reset, $$NF}' $(MAKEFILE_LIST) | sort
3017
@echo ""
3118

3219
# ==================================================================================== #
33-
# PRIVATE BUILDERS
20+
# PRIVATE TARGETS
3421
# ==================================================================================== #
35-
_process_templ_files:
36-
@echo "$(color_magenta)Process TEMPL files$(color_reset)"
37-
38-
@echo "$(color_cyan) * Formatting templ files...$(color_reset)"
39-
@templ fmt .
40-
41-
@echo "$(color_cyan) * Generating templ funcs...$(color_reset)"
42-
@templ generate
43-
44-
@echo "$(color_green)Done!$(color_reset)"
22+
.PHONY: modernize
23+
modernize:
24+
@modernize -test ./...
4525

46-
_go_tools:
47-
@echo ""
48-
@echo "$(color_magenta)Run go tools...$(color_reset)"
49-
50-
@echo "$(color_cyan) * Downloading modules...$(color_reset)"
51-
@go mod download; go mod tidy
52-
@go build -v ./...
53-
@echo "$(color_cyan) * Running golangci-lint...$(color_reset)"
26+
.PHONY: lint
27+
lint:
5428
@golangci-lint run ./...
55-
@echo "$(color_cyan) * Running tests...$(color_reset)"
56-
@$(MAKE) _test
57-
58-
@echo "$(color_green)Done!$(color_reset)"
5929

60-
_test:
61-
@go test -race -covermode=atomic ./...
30+
.PHONY: test/view-total-coverage
31+
test/view-total-coverage:
32+
@echo ""
33+
@echo "Total Coverage:"
34+
@go tool cover -func=profile.cov | grep total | awk -F '[[:space:]]+' '{print $$NF}'
35+
36+
.PHONY: test/view-coverage
37+
test/view-coverage:
38+
@go tool cover -html=profile.cov
39+
@echo "Coverage report displayed in your default browser."
40+
41+
.PHONY: live/templ
42+
live/templ:
43+
@templ generate --watch --proxy="http://localhost:3300" --open-browser=true
44+
45+
.PHONY: live/server
46+
live/server:
47+
@go run github.com/air-verse/[email protected] \
48+
--build.cmd "go build -o tmp/bin/main ./examples" \
49+
--build.bin "tmp/bin/main" \
50+
--build.delay "100" \
51+
--build.exclude_dir "assets,docs" \
52+
--build.include_ext "go" \
53+
--build.stop_on_error "false" \
54+
--misc.clean_on_exit true
55+
56+
.PHONY: live/sync
57+
live/sync:
58+
@go run github.com/air-verse/[email protected] \
59+
--build.cmd "tempo sync && templ generate -notify-proxy" \
60+
--build.bin "true" \
61+
--build.delay "100" \
62+
--build.exclude_dir "" \
63+
--build.include_dir "assets" \
64+
--build.include_ext "js,css"
6265

6366
# ==================================================================================== #
64-
# BUILDERS
67+
# PUBLIC TARGETS
6568
# ==================================================================================== #
66-
67-
examples: ## Process templ files in the _examples folder
68-
@for example in $(EXAMPLES); do \
69-
pushd $$example && templ fmt . && templ generate && popd; \
70-
done
71-
72-
test: ## Run go tests
73-
@$(MAKE) _test
74-
75-
templ: ## Process TEMPL files
76-
@$(MAKE) _process_templ_files
77-
78-
clean:
79-
@echo ""
80-
@echo "$(color_magenta)Clean up$(color_reset)"
81-
@find . -type f -name '*.grc.bk' -exec rm -f {} +
82-
@find . -type f -name '*_templ.txt' -exec rm -f {} +
83-
@echo "$(color_green)Done!$(color_reset)"
84-
85-
build: ## The main build target
86-
@$(MAKE) templ _go_tools
69+
.PHONY: test
70+
test: ## Run all tests and generate coverage report
71+
@go test -count=1 -timeout 30s $(shell go list ./... | grep -Ev 'examples|components') -covermode=atomic -coverprofile=profile.cov
72+
@$(MAKE) test/view-total-coverage
73+
74+
.PHONY: test/coverage
75+
test/coverage: ## Run go tests and use go tool cover
76+
@$(MAKE) test/force
77+
@$(MAKE) test/view-coverage
78+
79+
.PHONY: test/force
80+
test/force: ## Clean go tests cache and run all tests
81+
@go clean -testcache
82+
@$(MAKE) test
83+
84+
.PHONY: templ
85+
templ: ## Run all tests and generate coverage report
86+
@templ fmt . && templ generate
87+
88+
.PHONY: dev
89+
dev: ## Run the dev server with live reload
90+
make -j3 live/templ live/server live/sync
91+
92+
.PHONY: pre-build
93+
pre-build: ## Run pre-build tasks
94+
@$(MAKE) modernize
95+
@$(MAKE) lint
96+
@$(MAKE) test/force
97+
98+
.PHONY: build
99+
build: ## Build for production with minified asset files
100+
@$(MAKE) pre-build
101+
@tempo sync --prod
102+
@$(MAKE) templ

Taskfile.yaml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
version: '3'
2+
3+
tasks:
4+
# ==================================================================================== #
5+
# Private Tasks
6+
# ==================================================================================== #
7+
modernize:
8+
desc: Run go-modernize
9+
silent: true
10+
internal: true
11+
cmds:
12+
- modernize -test ./...
13+
14+
lint:
15+
desc: Run golangci-lint
16+
silent: true
17+
internal: true
18+
cmds:
19+
- golangci-lint run ./...
20+
21+
test/view-total-coverage:
22+
desc: Display total test coverage from profile.cov
23+
silent: true
24+
internal: true
25+
cmds:
26+
- echo ""
27+
- echo "Total Coverage:"
28+
- go tool cover -func=profile.cov | grep total | awk -F '[[:space:]]+' '{print $NF}'
29+
30+
test/view-coverage:
31+
desc: View the HTML coverage report
32+
silent: true
33+
internal: true
34+
cmds:
35+
- go tool cover -html=profile.cov
36+
- echo "Coverage report displayed in your default browser."
37+
38+
live:templ:
39+
desc: Run templ generation in watch mode
40+
silent: true
41+
internal: true
42+
cmds:
43+
- templ generate --watch --proxy="http://localhost:3300" --open-browser=true
44+
45+
live:server:
46+
desc: Run air to detect file changes, re-build and re-run the server
47+
silent: true
48+
internal: true
49+
cmds:
50+
- |
51+
go run github.com/air-verse/[email protected] \
52+
--build.cmd "go build -o tmp/bin/main ./examples" \
53+
--build.bin "tmp/bin/main" \
54+
--build.delay "100" \
55+
--build.exclude_dir "assets,docs" \
56+
--build.include_ext "go" \
57+
--build.stop_on_error "false" \
58+
--misc.clean_on_exit true
59+
60+
live:sync:
61+
desc: Watch for asset changes and reload browser via templ proxy
62+
silent: true
63+
internal: true
64+
cmds:
65+
- |
66+
go run github.com/air-verse/[email protected] \
67+
--build.cmd "tempo sync && templ generate -notify-proxy" \
68+
--build.bin "true" \
69+
--build.delay "100" \
70+
--build.exclude_dir "" \
71+
--build.include_dir "assets" \
72+
--build.include_ext "js,css"
73+
74+
# ==================================================================================== #
75+
# Public Tasks
76+
# ==================================================================================== #
77+
test:
78+
desc: Run all tests and generate coverage report
79+
silent: false
80+
cmds:
81+
- go test -count=1 -timeout 30s $(go list ./... | grep -Ev 'examples|components') -covermode=atomic -coverprofile=profile.cov
82+
- task: test/view-total-coverage
83+
84+
test/coverage:
85+
desc: Run go tests and use go tool cover
86+
silent: false
87+
deps:
88+
- test/force
89+
cmds:
90+
- task: test/view-coverage
91+
92+
test/force:
93+
desc: Clean go tests cache and run all tests
94+
silent: false
95+
cmds:
96+
- go clean -testcache
97+
- task: test
98+
99+
templ:
100+
desc: Run templ fmt and templ generate commands
101+
silent: false
102+
cmds:
103+
- templ fmt . && templ generate
104+
105+
dev:
106+
desc: Run the dev server with live reload
107+
silent: false
108+
deps:
109+
- live:templ
110+
- live:server
111+
- live:sync
112+
113+
pre-build:
114+
desc: Run pre-build tasks
115+
silent: false
116+
deps:
117+
- modernize
118+
- lint
119+
- test/force
120+
121+
build:
122+
desc: Build for production with minified asset files
123+
deps:
124+
- pre-build
125+
cmds:
126+
- tempo sync --prod
127+
- task: templ

0 commit comments

Comments
 (0)