This repository has been archived by the owner on Oct 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
419 lines (315 loc) · 9.44 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# const
NVM:=$(shell nvm -v 2>/dev/null)
GO:=$(shell go version 2>/dev/null)
DOCKER:=$(shell docker -v 2>/dev/null)
DOCKER_COMPOSE:=$(shell docker compose version 2>/dev/null)
HOOKS_DIR=$(shell git rev-parse --show-toplevel)/.hooks
GIT_DIR=$(shell git rev-parse --absolute-git-dir)
GIT_HOOKS_DIR=$(GIT_DIR)/hooks
COMMIT_MSG_HOOK=commit-msg
PRE_COMMIT_HOOK=pre-commit
UI_DIR=ui
CORE_DIR=core
PRODUCER_DIR=producer
STACK_DIR=stack
TEST_DIR=test
TEST_NOTIFICATIONS_SERVER_DIR=notifications-server
TEST_WS_CLIENT_DIR=ws-client
CONFIG_FILENAME=notipie.config.json
EXAMPLE_CONFIG_FILENAME=notipie.config.example.json
UI_CONFIG_FILENAME=$(CONFIG_FILENAME)
EXAMPLE_UI_CONFIG_FILENAME=$(EXAMPLE_CONFIG_FILENAME)
CORE_CONFIG_FILENAME=$(CONFIG_FILENAME)
EXAMPLE_CORE_CONFIG_FILENAME=$(EXAMPLE_CONFIG_FILENAME)
.PHONY: clean
# install & no-params
all: print-env-help install copy-example-configs
print-env-help: print-env-help-ui print-env-help-core print-env-help-stack
print-env-help-ui:
ifneq ($(NVM_DIR),"")
@echo "> nvm installed, run 'nvm install' and 'nvm use' in your shell"
else ifneq ("$(wildcard $(HOME)/.nvm/nvm.sh)","")
@echo "> nvm installed, run 'nvm install' and 'nvm use' in your shell"
else
$(error nvm not installed, consider installing it or install latest LTS node.js manually)
endif
print-env-help-core:
ifdef GO
@echo "> go installed"
@echo "> $(shell go version)"
else
$(error go not installed, install version specified in 'core/go.mod' or later)
endif
print-env-help-stack: print-env-help-docker print-env-help-docker-compose
print-env-help-docker:
ifdef DOCKER
@echo "> docker installed"
@echo "> $(shell docker -v)"
else
$(warning docker not installed, install to build docker images)
endif
print-env-help-docker-compose:
ifdef DOCKER_COMPOSE
@echo "> docker compose installed"
@echo "> $(shell docker compose version)"
else
$(warning docker compose not installed, install to use docker-compose.yml)
endif
copy-example-configs: copy-example-config copy-configs
@echo "> configs copied"
copy-example-config:
@test -f $(CONFIG_FILENAME) && \
echo "> config already exists" || (\
cp $(EXAMPLE_CONFIG_FILENAME) $(CONFIG_FILENAME) && \
echo "> example config copied ($(EXAMPLE_CONFIG_FILENAME) => $(CONFIG_FILENAME))" \
)
copy-configs: copy-config-ui copy-config-core
copy-config-ui:
@test -f $(UI_DIR)/$(UI_CONFIG_FILENAME) && \
echo "> config for ui already exists" || (\
cp $(CONFIG_FILENAME) $(UI_DIR)/$(UI_CONFIG_FILENAME) && \
echo "> config for ui copied ($(CONFIG_FILENAME) => $(UI_DIR)/$(UI_CONFIG_FILENAME))" \
)
copy-config-core:
@test -f $(CORE_DIR)/$(CORE_CONFIG_FILENAME) && \
echo "> config for core already exists" || (\
cp $(CONFIG_FILENAME) $(CORE_DIR)/$(CORE_CONFIG_FILENAME) && \
echo "> config for core copied ($(CONFIG_FILENAME) => $(CORE_DIR)/$(CORE_CONFIG_FILENAME))" \
)
@cd $(CORE_DIR); \
$(MAKE) copy-example-configs
uc: update-configs
update-configs: copy-example-config update-config-ui update-config-core
@echo "> configs updated ($(CONFIG_FILENAME) => $(UI_DIR)/$(UI_CONFIG_FILENAME), $(CONFIG_FILENAME) => $(CORE_DIR)/$(CORE_CONFIG_FILENAME))"
update-config-ui:
@cp $(CONFIG_FILENAME) $(UI_DIR)/$(UI_CONFIG_FILENAME)
@echo "> config updated ($(CONFIG_FILENAME) => $(UI_DIR)/$(UI_CONFIG_FILENAME))"
update-config-core:
@cp $(CONFIG_FILENAME) $(CORE_DIR)/$(CORE_CONFIG_FILENAME)
@echo "> config updated ($(CONFIG_FILENAME) => $(CORE_DIR)/$(CORE_CONFIG_FILENAME))"
install: install-hooks install-ui install-core install-producer install-test
@echo "> workspace ready"
install-hooks: clean-hooks
@ln -s $(HOOKS_DIR)/$(PRE_COMMIT_HOOK) $(GIT_HOOKS_DIR)/$(PRE_COMMIT_HOOK)
@ln -s $(HOOKS_DIR)/$(COMMIT_MSG_HOOK) $(GIT_HOOKS_DIR)/$(COMMIT_MSG_HOOK)
clean-hooks:
@rm -f $(GIT_HOOKS_DIR)/*
install-ui: pre-install-ui
@cd $(UI_DIR); \
yarn
@echo "> workspace for ui synced"
pre-install-ui:
@cp -r .yarnrc.yml .yarn $(UI_DIR)
@echo "> configured yarn for ui"
install-core:
@cd $(CORE_DIR); \
$(MAKE) sync; \
$(MAKE) tidy
@echo "> workspace for core synced"
install-producer:
@cd $(PRODUCER_DIR); \
$(MAKE) sync; \
$(MAKE) tidy
@echo "> workspace for producer synced"
install-test: install-test-notifications-server install-test-ws-client
install-test-notifications-server: pre-install-test-notifications-server
@cd $(TEST_DIR)/$(TEST_NOTIFICATIONS_SERVER_DIR); \
yarn
@echo "> workspace for $(TEST_DIR)/$(TEST_NOTIFICATIONS_SERVER_DIR) synced"
pre-install-test-notifications-server:
@cp -r .yarnrc.yml .yarn $(TEST_DIR)/$(TEST_NOTIFICATIONS_SERVER_DIR)
@echo "> configured yarn for notifications-server"
install-test-ws-client: pre-install-test-ws-client
@cd $(TEST_DIR)/$(TEST_WS_CLIENT_DIR); \
yarn
@echo "> workspace for $(TEST_DIR)/$(TEST_WS_CLIENT_DIR) synced"
pre-install-test-ws-client:
@cp -r .yarnrc.yml .yarn $(TEST_DIR)/$(TEST_WS_CLIENT_DIR)
@echo "> configured yarn for ws-client"
# clean
nuke: clean remove-configs
@cd $(UI_DIR); \
rm -rf node_modules; \
rm -rf .yarn; \
rm -f .yarnrc.yml
@cd $(TEST_DIR)/$(TEST_NOTIFICATIONS_SERVER_DIR); \
rm -rf node_modules; \
rm -rf .yarn; \
rm -f .yarnrc.yml
@cd $(TEST_DIR)/$(TEST_WS_CLIENT_DIR); \
rm -rf node_modules; \
rm -rf .yarn; \
rm -f .yarnrc.yml
@echo "> nuked all node_modules and yarn configs"
rmc: remove-configs
remove-configs: remove-configs-ui remove-configs-core
@rm -f $(CONFIG_FILENAME)
@echo "> configs removed"
remove-configs-ui:
@rm -f $(UI_DIR)/$(UI_CONFIG_FILENAME)
@echo "> config for ui removed"
remove-configs-core:
@rm -f $(CORE_DIR)/$(CORE_CONFIG_FILENAME)
@echo "> config for core removed"
clean: clean-ui clean-core clean-test
@echo "> cleaned"
clean-ui:
@cd $(UI_DIR); \
rm -rf dist; \
rm -rf storybook-static
@echo "> removed dist and storybook-static from ui"
clean-core:
@cd $(CORE_DIR); \
$(MAKE) clean
@echo "> cleaned core"
clean-test: clean-test-notifications-server clean-test-ws-client
clean-test-notifications-server:
@cd $(TEST_DIR)/$(TEST_NOTIFICATIONS_SERVER_DIR); \
rm -rf build
clean-test-ws-client:
@cd $(TEST_DIR)/$(TEST_WS_CLIENT_DIR); \
rm -rf build
# build
b: build # run with -j2 or more for performance
bui: build-ui
bstorybook: build-storybook
bcore: build-core
bproducer: build-producer
bt: build-test
build: build-ui build-storybook build-core build-producer # run with -j2 or more for performance
@echo "> built"
build-ui:
@cd $(UI_DIR); \
yarn build
@echo "> built dist in ui"
build-storybook:
@cd $(UI_DIR); \
yarn build-storybook
@echo "> built storybook in ui"
build-core:
@cd $(CORE_DIR); \
$(MAKE) build
@echo "> built binary in core"
build-producer:
@cd $(PRODUCER_DIR); \
$(MAKE) build
@echo "> built binary in producer"
build-test: build-test-notifications-server build-test-ws-client
build-test-notifications-server:
@cd $(TEST_DIR)/$(TEST_NOTIFICATIONS_SERVER_DIR); \
yarn build
build-test-ws-client:
@cd $(TEST_DIR)/$(TEST_WS_CLIENT_DIR); \
yarn build
# docker
docker-build: docker-build-ui docker-build-core
docker-build-ui: build-ui
@cd $(UI_DIR); \
yarn docker-build
@echo "> docker image notipie-ui built"
docker-build-core:
@cd $(CORE_DIR); \
$(MAKE) docker-build
@echo "> docker image notipie-core built"
docker-compose-up:
@cd $(STACK_DIR); \
docker compose up
docker-compose-up-d:
@cd $(STACK_DIR); \
docker compose up -d
docker-compose-down:
@cd $(STACK_DIR); \
docker compose down
# dev
d: dev # run with -j2 or more
dui: dev-ui
dcore: dev-core
dtns: dev-test-notifications-server
dtwc: dev-test-websocket-client
dev: print-multithread-notice dev-ui dev-core # run with -j2 or more
print-multithread-notice:
@echo "> check if you are running make with -j2 or more"
dev-ui:
@cd $(UI_DIR); \
yarn dev
dev-core:
@cd $(CORE_DIR); \
$(MAKE) run
dev-test-notifications-server:
@cd $(TEST_DIR)/$(TEST_NOTIFICATIONS_SERVER_DIR); \
yarn start
dev-test-websocket-client:
@cd $(TEST_DIR)/$(TEST_WS_CLIENT_DIR)
yarn start
# test
t: test # run with -j2 or more for performance
tui: test-ui
tcore: test-core
tproducer: test-producer
tr: test-race
test: test-ui test-core test-producer # run with -j2 or more for performance
@echo "> tests completed"
test-ui:
@cd $(UI_DIR); \
yarn test
@echo "> completed tests in ui"
test-core:
@cd $(CORE_DIR); \
$(MAKE) test
@echo "> completed tests in core"
test-producer:
@cd $(PRODUCER_DIR); \
$(MAKE) test
@echo "> completed tests in producer"
test-race: test-core-race test-producer-race
@echo "> tests with race detection completed"
test-core-race:
@cd $(CORE_DIR); \
$(MAKE) test-race
@echo "> completed tests in core with race detection"
test-producer-race:
@cd $(PRODUCER_DIR); \
$(MAKE) test-race
@echo "> completed tests in producer with race detection"
# lint
lint-fix: lint-ui-fix lint-core lint-producer
@echo "> linted and fixed"
lint-ui-fix:
@cd $(UI_DIR); \
yarn lint:fix
@echo "> linted and fixed ui"
lint: lint-ui lint-core lint-producer
@echo "> linted"
lint-ui:
@cd $(UI_DIR); \
yarn lint
@echo "> linted ui"
lint-core:
@cd $(CORE_DIR); \
$(MAKE) lint
@echo "> linted core"
lint-producer:
@cd $(PRODUCER_DIR); \
$(MAKE) lint
@echo "> linted producer"
# format
format: format-ui format-core
@echo "> formatted"
format-ui:
@cd $(UI_DIR); \
yarn format
@echo "> formatted ui"
format-core:
@cd $(CORE_DIR); \
$(MAKE) format
@echo "> formatted core"
# pre-commit check
pre-commit: pre-commit-core pre-commit-ui
@echo "> pre-commit all ok"
pre-commit-core:
@cd $(CORE_DIR); \
$(MAKE) pre-commit
pre-commit-ui:
@cd $(UI_DIR); \
yarn pre-commit
@echo "> ui > pre-commit ok"