forked from zekroTJA/shinpuru
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
157 lines (126 loc) · 3.51 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
### NAMES AND LOCS ############################
APPNAME = shinpuru
PACKAGE = github.com/zekroTJA/shinpuru
LDPAKAGE = internal/util
CONFIG = $(CURDIR)/config/private.config.yml
BINPATH = $(CURDIR)/bin
PRETTIER_CFG = "$(CURDIR)/.prettierrc.yml"
TMPBIN = "./bin/tmp/$(APPNAME)"
###############################################
### EXECUTABLES ###############################
GO = go
GOLINT = golint
GREP = grep
PRETTIER = prettier
YARN = yarn
DOCKERCOMPOSE = docker-compose
SWAGGO = swag
SWAGGER2MD = swagger-markdown
###############################################
# ---------------------------------------------
BIN = $(BINPATH)/$(APPNAME)
TAG = $(shell git describe --tags)
COMMIT = $(shell git rev-parse HEAD)
DATE = $(shell date +%s)
ifneq ($(GOOS),)
BIN := $(BIN)_$(GOOS)
endif
ifneq ($(GOARCH),)
BIN := $(BIN)_$(GOARCH)
endif
ifneq ($(TAG),)
BIN := $(BIN)_$(TAG)
endif
ifeq ($(OS),Windows_NT)
ifeq ($(GOOS),)
BIN := $(BIN).exe
endif
endif
ifeq ($(GOOS),windows)
BIN := $(BIN).exe
endif
PHONY = _make
_make: deps fe copyfe build cleanup
PHONY += build
build: $(BIN)
PHONY += deps
deps:
$(GO) mod tidy
cd ./web && \
$(YARN) install
$(BIN):
$(GO) build \
-v -o $@ -ldflags "\
-X $(PACKAGE)/$(LDPAKAGE).AppVersion=$(TAG) \
-X $(PACKAGE)/$(LDPAKAGE).AppCommit=$(COMMIT) \
-X $(PACKAGE)/$(LDPAKAGE).AppDate=$(DATE) \
-X $(PACKAGE)/$(LDPAKAGE).Release=TRUE" \
$(CURDIR)/cmd/$(APPNAME)/*.go
PHONY += test
test:
$(GO) test -race -v -cover ./...
PHONY += lint
lint:
$(GOLINT) ./... | $(GREP) -v vendor || true
$(TMPBIN):
$(GO) build -race -v -o $@ $(CURDIR)/cmd/$(APPNAME)/*.go
PHONY += run
run: $(TMPBIN)
$(TMPBIN) -c $(CONFIG) -quiet
PHONY += rundev
rundev: $(TMPBIN)
$(TMPBIN) -devmode -c $(CONFIG) -quiet
PHONY += cleanup
cleanup:
PHONY += fe
fe:
cd $(CURDIR)/web && \
$(YARN) run build
PHONY += copyfe
copyfe:
cp -R web/dist/web/* internal/util/embedded/webdist
PHONY += runfe
runfe:
cd ./web && $(YARN) start
PHONY += prettify
prettify:
$(PRETTIER) \
--config $(PRETTIER_CFG) \
--write \
$(CURDIR)/web/src/**/*.js \
$(CURDIR)/web/src/**/**/*.js \
$(CURDIR)/web/src/**/*.vue \
$(CURDIR)/web/src/**/**/*.vue
PHONY += devstack
devstack:
$(DOCKERCOMPOSE) -f docker-compose.dev.yml \
up -d
PHONY += devstack
APIDOCS_OUTDIR = "$(CURDIR)/docs/restapi/v1"
apidocs:
$(SWAGGO) init \
-g $(CURDIR)/internal/services/webserver/v1/router.go \
-o $(APIDOCS_OUTDIR) \
--parseDependency --parseDepth 2
rm $(APIDOCS_OUTDIR)/docs.go
$(SWAGGER2MD) -i $(APIDOCS_OUTDIR)/swagger.json -o $(APIDOCS_OUTDIR)/restapi.md
PHONY += help
help:
@echo "Available targets:"
@echo " # - creates binary in ./bin"
@echo " cleanup - tidy up temporary stuff created by build or scripts"
@echo " deps - ensure dependencies are installed"
@echo " devstack - spins up the dev docker-compose stack"
@echo " fe - build font end files"
@echo " lint - run linters (golint)"
@echo " run - debug run app (go run) with test config"
@echo " runfe - debug run front end vue live-server"
@echo " test - run tests (go test)"
@echo ""
@echo "Cross Compiling:"
@echo " (env GOOS=linux GOARCH=arm make)"
@echo ""
@echo "Use different configs for run:"
@echo " make CONF=./myCustomConfig.yml run"
@echo ""
.PHONY: $(PHONY)