/
Makefile
104 lines (88 loc) · 2.33 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
.DEFAULT_GOAL:=help
.PHONY: test
## Run go test
test:
go test -v ./...
.PHONY: install
## Run go install
install:
go install cmd/gotsrpc/gotsrpc.go
## Run go install with debug
install.debug:
go install -gcflags "all=-N -l" cmd/gotsrpc/gotsrpc.go
.PHONY: outdated
## Show outdated direct dependencies
outdated:
go list -u -m -json all | go-mod-outdated -update -direct
## === Tools ===
EXAMPLES=basic errors monitor nullable union time
define examples
.PHONY: example.$(1)
example.$(1):
cd example/${1} && go run ../../cmd/gotsrpc/gotsrpc.go gotsrpc.yml
cd example/${1}/client && ../../node_modules/.bin/tsc --build
.PHONY: example.$(1).run
example.$(1).run: example.${1}
cd example/${1} && go run main.go
.PHONY: example.$(1).debug
example.$(1).debug: build.debug
cd example/${1} && dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ../../bin/gotsrpc gotsrpc.yml
.PHONY: example.$(1).lint
example.$(1).lint:
cd example/${1} && golangci-lint run
endef
$(foreach p,$(EXAMPLES),$(eval $(call examples,$(p))))
## Run go mod tidy recursive
.PHONY: lint
lint:
@golangci-lint run
.PHONY: lint.fix
lint.fix:
@golangci-lint run --fix
.PHONY: tidy
## Run go mod tidy recursive
tidy:
@go mod tidy
## === Examples ===
.PHONY: examples
## Build examples
examples:
@for name in example/*/; do\
if [ $$name != "example/node_modules/" ]; then \
echo "-------- $${name} ------------";\
$(MAKE) example.`basename $${name}`;\
fi \
done
.PHONY: examples
## === Utils ===
## Show help text
help:
@awk '{ \
if ($$0 ~ /^.PHONY: [a-zA-Z\-\_0-9]+$$/) { \
helpCommand = substr($$0, index($$0, ":") + 2); \
if (helpMessage) { \
printf "\033[36m%-23s\033[0m %s\n", \
helpCommand, helpMessage; \
helpMessage = ""; \
} \
} else if ($$0 ~ /^[a-zA-Z\-\_0-9.]+:/) { \
helpCommand = substr($$0, 0, index($$0, ":")); \
if (helpMessage) { \
printf "\033[36m%-23s\033[0m %s\n", \
helpCommand, helpMessage"\n"; \
helpMessage = ""; \
} \
} else if ($$0 ~ /^##/) { \
if (helpMessage) { \
helpMessage = helpMessage"\n "substr($$0, 3); \
} else { \
helpMessage = substr($$0, 3); \
} \
} else { \
if (helpMessage) { \
print "\n "helpMessage"\n" \
} \
helpMessage = ""; \
} \
}' \
$(MAKEFILE_LIST)