This repository has been archived by the owner on Jan 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile
274 lines (200 loc) · 5.89 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
VERSION ?= 1.0.0
IMAGE_NAME := instrumentisto/vue-app-example
NODE_VERSION := latest
NODE_ALPINE_VERSION := alpine
SELENIUM_CHROME_VERSION := latest
SELENIUM_FIREFOX_VERSION := 3.4.0
DIST_DIR := _dist
MAINLINE_BRANCH := dev
CURRENT_BRANCH := $(shell git branch | grep \* | cut -d ' ' -f2)
cmd ?= !default
dev ?= yes
no-cache ?= no
comma := ,
empty :=
space := $(empty) $(empty)
eq = $(if $(or $(1),$(2)),$(and $(findstring $(1),$(2)),\
$(findstring $(2),$(1))),1)
# Build project from sources.
#
# Usage:
# make build [dev=(yes|no)] [target=(all|client|server)]
env ?= $(if $(call eq,$(dev),yes),development,production)
target ?= all
build:
docker run --rm -v $(PWD):/app -w /app -e NODE_ENV=$(env) \
node:$(NODE_ALPINE_VERSION) \
yarn build:$(target)
# Resolve all project dependencies.
#
# Usage:
# make deps [dev=(yes|no)]
deps: deps.yarn deps.docker
ifeq ($(wildcard $(DIST_DIR)),)
mkdir -p $(DIST_DIR)
endif
# Resolve project dependencies with Yarn.
#
# Optional 'cmd' parameter may be used for handy usage of docker-wrapped Yarn,
# for example: `make deps.yarn cmd="update"`.
#
# Usage:
# make deps.yarn [cmd=] [dev=(yes|no)]
yarn-args = $(if $(call eq,$(cmd),!default),install,$(cmd))
yarn-args-full = $(yarn-args) \
$(if $(and $(call eq,$(dev),no),\
$(call eq,$(yarn-args),install)),\
--production,)
deps.yarn:
docker run --rm -v $(PWD):/app -w /app \
-e YARN_CACHE_FOLDER=/app/_cache/yarn \
node:$(NODE_ALPINE_VERSION) \
yarn $(yarn-args-full)
# Resolve project Docker dependencies.
#
# Usage:
# make deps.docker
deps.docker:
docker pull node:$(NODE_VERSION)
docker pull node:$(NODE_ALPINE_VERSION)
docker pull selenium/standalone-chrome:$(SELENIUM_CHROME_VERSION)
docker pull selenium/standalone-firefox:$(SELENIUM_FIREFOX_VERSION)
# Lint project TypeScript sources with TSLint.
#
# Usage:
# make lint
lint:
docker run --rm -v $(PWD):/app -w /app \
node:$(NODE_ALPINE_VERSION) \
yarn lint
# Run all project tests.
#
# Usage:
# make test
test: test.unit test.e2e test.docker
# Run unit tests for project with Karma.
#
# Usage:
# make test.unit [watch=(no|yes)]
unit-watch-prefix = $(if $(call eq,$(watch),yes),watch:,)
test.unit:
docker run --rm -v $(PWD):/app -w /app node:$(NODE_VERSION) \
yarn $(unit-watch-prefix)test:unit
# Run Nightwatch.js E2E tests for project.
#
# Usage:
# make test.e2e [start-app=(no|yes)]
# [browsers=chrome,firefox]
# [watch=(no|yes)]
start-app ?= no
browsers ?= chrome,firefox
selenium-chrome-port := 4444
selenium-firefox-port := 4445
e2e-watch-prefix = $(if $(call eq,$(watch),yes),watch:,)
test.e2e:
ifeq ($(start-app),yes)
-@docker-compose down
docker-compose up -d
endif
$(foreach browser,$(subst $(comma), ,$(browsers)), \
$(call checkSeleniumStarted,$(browser)))
$(foreach browser,$(subst $(comma), ,$(browsers)), \
$(if $(call eq,$(run-selenium-$(browser)),yes), \
$(call startSelenium,$(browser)),))
docker run --rm --net=host -v $(PWD):/app -w /app \
-e NOT_START_SELENIUM=1 \
-e E2E_BROWSERS=$(browsers) \
node:$(NODE_ALPINE_VERSION) \
yarn $(e2e-watch-prefix)test:e2e
$(foreach browser,$(subst $(comma), ,$(browsers)), \
$(if $(call eq,$(run-selenium-$(browser)),yes), \
$(call stopSelenium,$(browser)),))
ifeq ($(start-app),yes)
docker-compose down
endif
define checkSeleniumStarted
$(eval run-selenium-$(1) := \
$(if $(call eq,$(shell docker ps -q -f name=selenium-$(1)),),yes,))
endef
define startSelenium
$()
-@docker stop selenium-$(1)
-@docker rm selenium-$(1)
docker run -d --name=selenium-$(1) -p $(selenium-$(1)-port):4444 \
--net=vue-app-example_default \
--link=vue-app-example-nginx:vue-app-example.localhost \
--link=vue-app-example-json-server:api.vue-app-example.localhost \
-e DBUS_SESSION_BUS_ADDRESS=/dev/null \
selenium/standalone-$(1):$(SELENIUM_$(shell echo $(1) | tr a-z A-Z)_VERSION)
$(eval selenium-$(1)-started := yes)
endef
define stopSelenium
$()
docker stop selenium-$(1)
docker rm selenium-$(1)
endef
# Run Bats tests for project Docker image.
#
# Usage:
# make test.docker [VERSION=]
test.docker:
IMAGE=$(IMAGE_NAME):$(VERSION) node_modules/.bin/bats test/docker/suite.bats
# Generate Typedoc documentation of project TypeScript sources.
#
# Documentation of Typedoc tools:
# http://typedoc.org/guides/usage/
#
# Usage:
# make docs
docs:
docker run --rm -v $(PWD):/app -w /app node:$(NODE_ALPINE_VERSION) \
yarn docs
# Build project Docker image.
#
# Usage:
# make docker.image [no-cache=(yes|no)] [VERSION=]
no-cache-arg = $(if $(call eq,$(no-cache),yes),--no-cache,)
docker.image:
docker build $(no-cache-arg) -t $(IMAGE_NAME):$(VERSION) .
# Create distribution files of project.
#
# Usage:
# make dist
dist:
mkdir -p $(DIST_DIR)
rm -rf $(DIST_DIR)/*
cp -r node_modules public index.server.html server.js vue-ssr-bundle.json \
$(DIST_DIR)/
# Squash changes of the current Git branch onto another Git branch.
#
# WARNING: You must merge `onto` branch in the current branch before squash!
#
# Usage:
# make squash [onto=] [del=(no|yes)]
onto ?= $(MAINLINE_BRANCH)
del ?= no
upstream ?= origin
squash:
ifeq ($(CURRENT_BRANCH),$(onto))
@echo "--> Current branch is '$(onto)' already" && false
endif
git checkout $(onto)
git branch -m $(CURRENT_BRANCH) orig-$(CURRENT_BRANCH)
git checkout -b $(CURRENT_BRANCH)
git branch --set-upstream-to $(upstream)/$(CURRENT_BRANCH)
git merge --squash orig-$(CURRENT_BRANCH)
ifeq ($(del),yes)
git branch -d orig-$(CURRENT_BRANCH)
endif
# Clean all project files that is not under version control.
#
# WARNING: This will remove all your local untracked and ignored files!
#
# Usage:
# make clean
clean:
git clean -ffdx
.PHONY: build lint docs \
deps deps.yarn deps.docker \
test test.unit test.e2e test.docker \
docker.image dist squash clean