@@ -10,6 +10,8 @@ GOLANGCI_LINT=hack/bin/golangci-lint
10
10
GO_MOD_OUTDATED =hack/bin/go-mod-outdated
11
11
GOLIST =go list -f "{{ .Dir }}" -m
12
12
13
+ GORELEASER =hack/bin/goreleaser
14
+
13
15
export GO111MODULE =on
14
16
undefine GOARCH
15
17
undefine GOOS
@@ -70,17 +72,18 @@ genproto: vendor node_modules $(GOIMPORTS) $(PROTOWRAP) $(PROTOC_GEN_GO) $(PROTO
70
72
set -eo pipefail; \
71
73
export PROJECT=$$(go list -m ) ; \
72
74
export PATH=$$(pwd ) /hack/bin:$$ {PATH}; \
73
- export OUT=$$( pwd ) /vendor; \
75
+ export OUT=. /vendor; \
74
76
mkdir -p $$ {OUT}/$$(dirname $${PROJECT} ) ; \
75
- rm $$( pwd ) /vendor/$$ {PROJECT} || true ; \
76
- ln -s $$(pwd ) $$( pwd ) /vendor/$$ {PROJECT} ; \
77
+ rm . /vendor/$$ {PROJECT} || true ; \
78
+ ln -s $$(pwd ) . /vendor/$$ {PROJECT} ; \
77
79
protogen () { \
80
+ PROTO_FILES=$$(git ls-files "$$1" ) ; \
78
81
$(PROTOWRAP ) \
79
82
-I $$ {OUT} \
80
83
--plugin=./node_modules/.bin/protoc-gen-es \
81
84
--plugin=./node_modules/.bin/protoc-gen-es-starpc \
82
85
--go-lite_out=$$ {OUT} \
83
- --go-lite_opt=features=marshal+unmarshal+size+equal+clone+text+json \
86
+ --go-lite_opt=features=marshal+unmarshal+size+equal+json+ clone+text \
84
87
--go-starpc_out=$$ {OUT} \
85
88
--es_out=$$ {OUT} \
86
89
--es_opt target=ts \
@@ -91,16 +94,33 @@ genproto: vendor node_modules $(GOIMPORTS) $(PROTOWRAP) $(PROTOC_GEN_GO) $(PROTO
91
94
--proto_path $$ {OUT} \
92
95
--print_structure \
93
96
--only_specified_files \
94
- $$(\
95
- git \
96
- ls-files " $$ 1" | \
97
- xargs printf -- \
98
- " $$ (pwd)/vendor/$$ {PROJECT}/%s " ); \
97
+ $$(echo "$$PROTO_FILES" | xargs printf -- "./vendor/$${PROJECT}/%s " ) ; \
98
+ for proto_file in $$ {PROTO_FILES}; do \
99
+ proto_dir=$$(dirname $$proto_file ) ; \
100
+ proto_name=$$ {proto_file%" .proto" }; \
101
+ TS_FILES=$$(git ls-files ":(glob ) $$ {proto_dir}/${proto_name} * _pb.ts" ); \
102
+ if [ -z " $$ TS_FILES" ]; then continue ; fi ; \
103
+ for ts_file in $$ {TS_FILES}; do \
104
+ ts_file_dir=$$(dirname $$ts_file ) ; \
105
+ relative_path=$$ {ts_file_dir#" ./" }; \
106
+ depth=$$(echo $$relative_path | awk -F/ '{print NF+1}' ) ; \
107
+ prefix=$$(printf '../%0.s' $$(seq 1 $$depth ) ) ; \
108
+ istmts=$$(grep -oE "from\s+\"$$prefix[^\"]+\"" $$ts_file ) || continue ; \
109
+ if [ -z " $$ istmts" ]; then continue ; fi ; \
110
+ ipaths=$$(echo "$$istmts" | awk -F'"' '{print $$2}' ) ; \
111
+ for import_path in $$ ipaths; do \
112
+ rel_import_path=$$(realpath -s --relative-to=./vendor \
113
+ " ./vendor/$$ {PROJECT}/$$ {ts_file_dir}/$$ {import_path}" ); \
114
+ go_import_path=$$(echo $$rel_import_path | sed -e "s|^|@go/|" ) ; \
115
+ sed -i -e " s|$$ import_path|$$ go_import_path|g" $$ ts_file; \
116
+ done ; \
117
+ done ; \
118
+ done ; \
99
119
}; \
100
120
protogen " ./*.proto" ; \
101
- rm $$(pwd ) /vendor/$$ {PROJECT} || true
121
+ true || protogen " ./signaling/rpc/signaling.proto" ; \
122
+ rm -f ./vendor/$$ {PROJECT}
102
123
$(GOIMPORTS ) -w ./
103
- npm run format:js
104
124
105
125
.PHONY : gen
106
126
gen : genproto
@@ -129,3 +149,13 @@ test:
129
149
format : $(GOFUMPT ) $(GOIMPORTS )
130
150
$(GOIMPORTS ) -w ./
131
151
$(GOFUMPT ) -w ./
152
+
153
+ $(GORELEASER ) :
154
+ cd ./hack; \
155
+ go build -v \
156
+ -o ./bin/goreleaser \
157
+ github.com/goreleaser/goreleaser
158
+
159
+ .PHONY : release
160
+ release : $(GORELEASER )
161
+ $(GORELEASER ) release --clean
0 commit comments