-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
86 lines (71 loc) · 2.63 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
# can be overridden at runtime eg. `make build runner=grunt`
runner=gulp
help:
@echo "avengers-web-application"
@echo ""
@echo "The following commands are available:"
@echo ""
@echo "\tmake extract-translations - Extract i18n strings from JS/HBS files"
@echo "\tmake setup - Installs node dependencies and requisites for build"
@echo "\tmake watch - Triggers a watcher via preferred task runner"
@echo "\tmake <TASK> - Triggers specified task, e.g. 'make build'"
@echo ""
@echo ""
@echo "Docker based building is also available:"
@echo ""
@echo "\tmake docker cmd=<TASK> - Triggers specified task via docker, e.g. 'make docker cmd=build'"
@echo ""
default: help
extract-translations:
node_modules/.bin/jspot extract --keyword=i18n --target=./locales ./js/src/*.js ./js/src/templates/*.hbs;
watch: node_modules
$(runner);
# this allows any of the gulp commands to be called, e.g. `make scripts`
build test images lint scripts styles templates: node_modules
$(runner) $@;
# just install node_modules, also callable as `make node_modules`
setup: node_modules
# backwards compatibility
fe-setup: build
# this only runs if the modification date of `package.json` is more recent
# than the modification date of `node_modules`, `touch $@` updates the
# modification date of `node_modules` when done.
node_modules: package.json
npm cache clean;
npm install;
touch $@
# Variables for docker based building
IMAGE_NAME = fe-skeleton
BASE_CONTAINER_NAME = $(IMAGE_NAME)-$(runner)
# use a target flag file (.dockerbuild) so image is only rebuilt when
# Dockerfile has been changed more recently than last build
.dockerbuild: Dockerfile
-docker rm $(BASE_CONTAINER_NAME)-build
-docker rm $(BASE_CONTAINER_NAME)-watch
-docker rm $(BASE_CONTAINER_NAME)-test
docker build -t $(IMAGE_NAME) .
touch $@
# default docker command
cmd=build
# Here we check if a container with the correct name already exists and if
# it does we run it again. Otherwise we run a new one and have it call
# `make $(cmd) runner=$(runner)`
docker: .dockerbuild
@EXISTS=$$(docker ps -a | grep "$(BASE_CONTAINER_NAME)-$(cmd)" | awk '{ print $$1 }'); \
if [ $$EXISTS ]; then \
echo "Reusing existing container..."; \
docker start -ai $$EXISTS; \
else \
echo "Running a new container..."; \
docker run \
-ti \
--name $(BASE_CONTAINER_NAME)-$(cmd) \
-v $(CURDIR):/src \
$(IMAGE_NAME) \
make $(cmd) runner=$(runner); \
fi
docker-shell: .dockerbuild
docker run -ti --rm -v $(CURDIR):/src $(IMAGE_NAME) bash
# makefile ettiquette; mark rules without on-disk targets as PHONY
.PHONY: default help setup fe-setup docker
.PHONY: build watch test lint images scripts styles templates