-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
172 lines (136 loc) · 4.46 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
VERSION := $(shell cat VERSION)
VALIDATE_VERSION ?= v1.0.2
BUILD_DIR := .build/
GO ?= go
PROTOC ?= pnpm protoc
.DEFAULT: run-server
# Read .env file and export the vars
ifneq (,$(wildcard ./.env))
include .env
export
endif
build_dir:
mkdir -p $(BUILD_DIR)
# Build, Format, etc., Tools, Dependency checkouts
buf:
ifeq (, $(shell which buf))
$(GO) install github.com/bufbuild/buf/cmd/[email protected]
endif
protoc-gen-validate: build_dir
if test ! -d $(BUILD_DIR)validate-$(VALIDATE_VERSION)/; then \
git clone --branch $(VALIDATE_VERSION) https://github.com/bufbuild/protoc-gen-validate.git $(BUILD_DIR)validate-$(VALIDATE_VERSION); \
else \
git -C $(BUILD_DIR)validate-$(VALIDATE_VERSION)/ pull --all; \
git -C $(BUILD_DIR)validate-$(VALIDATE_VERSION)/ checkout $(VALIDATE_VERSION); \
fi
cd $(BUILD_DIR) && ln -sfn validate-$(VALIDATE_VERSION)/ validate
protoc-gen-customizer:
$(GO) build -o ./internal/cmd/protoc-gen-customizer ./internal/cmd/protoc-gen-customizer
protoc-gen-fronthelper:
$(GO) build -o ./internal/cmd/protoc-gen-fronthelper ./internal/cmd/protoc-gen-fronthelper
protoc-gen-doc:
$(GO) install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@latest
go-licenses:
ifeq (, $(shell which go-licenses))
@GO111MODULE=on $(GO) install github.com/google/go-licenses@latest
endif
# Actual targets
.PHONY: clean
clean:
@pnpx nuxi cleanup
rm -rf ./.nuxt/dist/
.PHONY: watch
watch:
pnpm dev
.PHONY: build-container
build-container:
docker build -t docker.io/fivenet-app/fivenet:latest \
--build-arg NUXT_UI_PRO_LICENSE=$(NUXT_UI_PRO_LICENSE) \
.
.PHONY: release
release:
docker tag docker.io/fivenet-app/fivenet:latest docker.io/fivenet-app/fivenet:$(VERSION)
.PHONY: tests
tests: tests-go
.PHONY: tests-go
tests-go:
$(GO) test -v ./...
.PHONY: build-go
build-go:
CGO_ENABLED=0 $(GO) \
build \
-a \
-installsuffix cgo \
-ldflags "-X github.com/fivenet-app/fivenet/pkg/version.Version=$(shell git describe --tags --exclude='fivenet-*')" \
-o fivenet .
.PHONY: build-js
build-js:
rm -rf ./.nuxt/dist/
pnpm build
.PHONY: run-server
run-server:
mkdir -p ./.nuxt/dist/
$(GO) run . server
.PHONY: gen
gen: gen-sql gen-proto
.PHONY: gen-sql
gen-sql:
$(GO) run ./query/gen/
# Remove schema/database name from the generated table code, so it uses the currently selected database
find ./query/fivenet/table -type f -iname '*.go' -exec sed -i 's~("fivenet", ~("", ~g' {} \;
.PHONY: gen-proto
gen-proto: protoc-gen-validate protoc-gen-customizer protoc-gen-fronthelper protoc-gen-doc
mkdir -p ./gen/go/proto
PATH="$$PATH:./internal/cmd/protoc-gen-customizer/" \
$(PROTOC) \
--proto_path=./$(BUILD_DIR)validate-$(VALIDATE_VERSION) \
--proto_path=./proto \
--go_out=./gen/go/proto \
--go_opt=paths=source_relative \
--go-grpc_out=./gen/go/proto \
--go-grpc_opt=paths=source_relative \
--validate_opt=paths=source_relative \
--validate_out="lang=go:./gen/go/proto" \
--customizer_opt=paths=source_relative \
--customizer_out=./gen/go/proto \
--doc_opt=./internal/protoc-gen-doc-md.tmpl,grpc-api.md \
--doc_out=./gen \
$(shell find proto/ -iname "*.proto")
# Inject Go field tags into generated fields
find ./gen/go/proto/ -iname "*.pb.go" \
-exec protoc-go-inject-tag \
-input={} \;
mkdir -p ./gen/ts
PATH="$$PATH:node_modules/@protobuf-ts/plugin/bin/:./internal/cmd/protoc-gen-fronthelper/" \
$(PROTOC) \
--proto_path=./$(BUILD_DIR)validate-$(VALIDATE_VERSION) \
--proto_path=./proto \
--ts_out=./gen/ts \
--ts_opt=optimize_speed,long_type_number,force_server_none \
--fronthelper_opt=paths=source_relative \
--fronthelper_out=./gen/ts \
$(shell find proto/ -iname "*.proto")
# Fix ignore TS typecheck comment
find ./gen/ts/ -type f -iname "*.ts" -print0 | \
xargs -0 sed -i 's~// tslint:disable~// @ts-nocheck~g'
.PHONY: fmt
fmt:
$(MAKE) fmt-proto gen-proto
$(MAKE) fmt-js
.PHONY: fmt-proto
fmt-proto: buf
buf format --write ./proto
.PHONY: fmt-js
fmt-js:
pnpm prettier --write ./app
.PHONY: gen-licenses
gen-licenses: go-licenses
$(MAKE) gen-licenses-js gen-licenses-go
gen-licenses-js:
pnpm licenses list --prod --json | \
pnpx @quantco/pnpm-licenses generate-disclaimer --json-input \
--output-file=./public/licenses/frontend.txt
gen-licenses-go:
go-licenses report ./... --ignore $$($(GO) list -m) --include_tests \
--ignore $$($(GO) list std | awk 'NR > 1 { printf(",") } { printf("%s",$$0) } END { print "" }') \
--template internal/scripts/go-licenses-backend.txt.tpl > ./public/licenses/backend.txt