forked from TomDoesTech/GOTTH
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
111 lines (103 loc) · 3.58 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
.PHONY: check-os
check-os:
@OS=$$(uname -s | tr '[:upper:]' '[:lower:]')-$$(uname -m); \
echo $$OS; \
if echo "$$OS" | grep -q -e 'mingw' -e '_nt'; then \
echo "Windows"; \
else \
echo "Linux/MacOS"; \
fi; \
.PHONY: check-os-then-build
check-os-then-build:
@OS=$$(uname -s | tr '[:upper:]' '[:lower:]')-$$(uname -m); \
if echo "$$OS" | grep -q -e 'mingw' -e '_nt'; then \
go build -o ./bin/$(APP_NAME).exe ./cmd/$(APP_NAME)/main.go && echo "Windows Build Successful"; \
else \
go build -o ./bin/$(APP_NAME) ./cmd/$(APP_NAME)/main.go && echo "Linux/MacOS Build Successful"; \
fi; \
.PHONY: check-os-then-dev-build
check-os-then-dev-build:
@OS=$$(uname -s | tr '[:upper:]' '[:lower:]')-$$(uname -m); \
if echo "$$OS" | grep -q -e 'mingw' -e '_nt'; then \
go build -o ./tmp/main.exe ./cmd/$(APP_NAME)/main.go && echo "Windows Build Successful"; \
else \
go build -o ./tmp/main ./cmd/$(APP_NAME)/main.go && echo "Linux/MacOS Build Successful"; \
fi; \
.PHONY: tailwind-watch
tailwind-watch:
npm run tailwind-watch; \
.PHONY: tailwind-build
tailwind-build:
npm run tailwind-build; \
echo "Tailwind Build Successful"; \
.PHONY: templ-generate
templ-generate:
@if command -v templ > /dev/null; then \
templ generate; \
echo "Templ Generated"; \
else \
/bin/echo -n "'Templ' is not installed on your machine. Do you want to install it? [Y/n] "; \
read choice; \
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
GO_VERSION=$$(go version | awk '{print $$3}' | tr -d 'go'); \
MIN_GO_VERSION=1.20; \
if [ "$$(printf '%s\n' "$$MIN_GO_VERSION" "$$GO_VERSION" | sort -V | head -n1)" = "$$MIN_GO_VERSION" ]; then \
echo "Installing templ..."; \
go install github.com/a-h/templ/cmd/templ@latest; \
templ generate; \
echo "Templ Generated"; \
else \
echo "templ requires golang version 1.20 or greater. Exiting..."; \
exit 1; \
fi; \
else \
echo "You chose not to install templ. Exiting..."; \
exit 1; \
fi; \
fi; \
.PHONY: sqlc-generate
sqlc-generate:
@if command -v sqlc > /dev/null; then \
sqlc generate; \
echo "SQLC Generated"; \
else \
/bin/echo -n "'Sqlc' is not installed on your machine. Do you want to install it? [Y/n] "; \
read choice; \
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
echo "Installing sqlc..."; \
GO_VERSION=$$(go version | awk '{print $$3}' | tr -d 'go'); \
MIN_GO_VERSION=1.17; \
if [ "$$(printf '%s\n' "$$MIN_GO_VERSION" "$$GO_VERSION" | sort -V | head -n1)" = "$$MIN_GO_VERSION" ]; then \
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest; \
sqlc generate; \
echo "SQLC Generated"; \
else \
go get github.com/sqlc-dev/sqlc/cmd/sqlc; \
sqlc generate; \
fi; \
else \
echo "You chose not to install sqlc. Exiting..."; \
exit 1; \
fi; \
fi; \
.PHONY: dev
dev:
@if command -v air > /dev/null; then \
make check-os-then-dev-build && air; \
echo "Watching...";\
else \
/bin/echo -n "Go's 'air' is not installed on your machine. Do you want to install it? [Y/n] "; \
read choice; \
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
echo "Installing air..."; \
go install github.com/cosmtrek/air@latest; \
make check-os-then-dev-build && air; \
echo "Watching...";\
else \
echo "You chose not to install air. Exiting..."; \
exit 1; \
fi; \
fi; \
.PHONY: build
build:
make tailwind-build && make templ-generate && make sqlc-generate && make check-os-then-build; \