-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
143 lines (108 loc) · 4.52 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
ifneq ($(wildcard ./.env),)
# $(info Loading environment variables from .env)
include ./.env
endif
YARN ?= $(shell command -v yarn || { \
echo 'ERROR: yarn must be installed globally to $$PATH to build this app'; \
exit 1; \
})
ifneq (,$(findstring ERROR:,$(YARN)))
$(error $(YARN))
endif
NODE ?= $(shell nvm which $(cat .nvmrc) 2>/dev/null || \
command -v node || \
{ \
echo 'ERROR: node or nvm must be installed an in $$PATH to build this app'; \
exit 1; \
})
ifneq (,$(findstring ERROR:,$(NODE)))
$(error $(NODE))
endif
NODE_MODULES :=./node_modules
NODE_MODULES_BIN :=$(NODE_MODULES)/.bin
JSPM_PACKAGES :=./static/jspm
TSC :=$(NODE_MODULES_BIN)/tsc
TSLINT :=$(NODE_MODULES_BIN)/tslint
NODEMON :=$(NODE_MODULES_BIN)/nodemon
JSPM :=$(NODE_MODULES_BIN)/jspm
YARN_FLAGS :=
NODE_FLAGS :=
TSC_FLAGS :=
TSLINT_FLAGS :=--format verbose $(shell [ ! -z "$(FIX)" -a "$(FIX)" != "0" ] && echo "--fix")
NODEMON_FLAGS :=--delay 0.5 --quiet --watch .env --watch index.js --watch dist --exec make start
SERVER_SRCS :=$(wildcard server/*.ts) $(wildcard server/*/*.ts) $(wildcard common/*.ts)
SERVER_OUTS :=$(addprefix dist/,$(SERVER_SRCS:.ts=.js))
CLIENT_SRCS :=$(wildcard client/*.ts) $(wildcard client/*/*.ts) $(wildcard common/*.ts)
CLIENT_OUTS :=$(addprefix static/js/,$(CLIENT_SRCS:.ts=.js)) static/js/jspm.config.js
.PHONY: all clean clean-modules install-yarn install-jspm pre-deps deps
.PHONY: build build-server build-client watch watch-server start start-watch
all: build lint
# Removes all files generated by the build (except node_modules)
clean:
@echo "==> Removing build files"
rm -rf dist static/js
clean-deps: clean
@echo "==> Removing installed dependencies"
rm -rf node_modules static/jspm
install-yarn:
@echo "==> Installing node_modules with yarn"
$(YARN) $(YARN_FLAGS) install
install-jspm: $(NODE_MODULES)
@echo "==> Installing jspm packages with jspm"
$(NODE) $(JSPM) install
pre-deps:
@echo "==> (Re-)installing all application dependencies"
deps: pre-deps install-yarn install-jspm
# Target to install node_modules if depended upon by other targets
$(NODE_MODULES): package.json yarn.lock
@[ -e "$(NODE_MODULES)" ] || (echo "==> $(NODE_MODULES) not found!" && make install-yarn)
$(TSC): package.json yarn.lock
@[ -e "$(TSC)" ] || (echo "==> $(TSC) not found!" && make YARN_FLAGS=--production=false install-yarn)
# Target to install jspm packages if depended upon by other targets
$(JSPM_PACKAGES): package.json
@[ -e "$(JSPM_PACKAGES)" ] || (echo "==> $(JSPM_PACKAGES) not found!" && make install-jspm)
pre-build:
@echo "==> Building tutor-match"
# Builds the entire app (excluding docker containers)
build: pre-build build-server build-client
@echo "==> Built tutor-match"
# Builds the server code (using typescript)
build-server: $(SERVER_OUTS)
$(SERVER_OUTS:.js=%js): $(NODE_MODULES) $(TSC) server/tsconfig.json $(SERVER_SRCS)
@echo "==> Building server"
$(NODE) $(TSC) $(TSC_FLAGS) --project server
# Builds the client code (using typescript)
build-client: $(CLIENT_OUTS) static/js/jspm.config.js static/js/client.bundle.js
$(CLIENT_OUTS:.js=%js): $(NODE_MODULES) $(JSPM_PACKAGES) $(TSC) client/tsconfig.json $(CLIENT_SRCS)
@echo "==> Building client"
$(NODE) $(TSC) $(TSC_FLAGS) --project client
static/js/jspm.config.js: jspm.config.js
cp $< $@
static/js/client.bundle.js: $(CLIENT_OUTS) jspm.config.js $(JSPM_PACKAGES)
@echo "==> Creating production client bundle"
$(NODE) $(JSPM) bundle './static/js/client/*' + ./static/jspm/github/systemjs/[email protected] $@ --minify
watch:
@echo "==> Watching all files for changes"
@scripts/parallel.sh "make watch-server" "make watch-client"
watch-server: $(NODE_MODULES) $(TSC)
@echo "==> Watching server for changes"
$(NODE) $(TSC) $(TSC_FLAGS) --project server --watch
watch-client: $(NODE_MODULES) $(TSC) $(JSPM_PACKAGES)
@echo "==> Watching client for changes"
$(NODE) $(TSC) $(TSC_FLAGS) --project client --watch
start:
# only build if not running on now.sh, and if in development
@! [ "$$NOW" != "1" -a "$$NODE_ENV" == "development" ] || make build
$(NODE) $(NODE_FLAGS) .
start-watch:
@echo "==> Restarting tutor-match on every rebuild"
@scripts/parallel.sh 'make watch' '$(NODE) $(NODEMON) $(NODEMON_FLAGS)'
# Lints everything
# Run with FIX=1 to automaticall fix some lint errors
lint: lint-server lint-client
lint-server: $(NODE_MODULES)
@echo "==> Linting server"
$(NODE) $(TSLINT) $(TSLINT_FLAGS) --project server
lint-client: $(NODE_MODULES)
@echo "==> Linting client"
$(NODE) $(TSLINT) $(TSLINT_FLAGS) --project client --exclude client/jspm.config.js