forked from stdlib-js/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
339 lines (237 loc) · 6.86 KB
/
Makefile
File metadata and controls
339 lines (237 loc) · 6.86 KB
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
# NOTE: this file should be located in the top-level application directory.
.PHONY: help
help:
@echo ''
@echo 'Usage: make <cmd>'
@echo ''
@echo ' make help Print this message.'
@echo ' make notes Search for code annotations.'
@echo ' make list-sources List all source files (excluding examples and tests).'
@echo ' make list-examples List all example files.'
@echo ' make list-tests List all test files.'
@echo ' make examples Run examples.'
@echo ' make test Run tests.'
@echo ' make test-summary Run tests and output a test summary.'
@echo ' make test-cov Run tests with code coverage.'
@echo ' make test-browsers Run tests in a local web browser.'
@echo ' make view-cov View the most recent code coverage report.'
@echo ' make view-browser-tests View browser tests in a local web browser.'
@echo ' make lint Run code linting.'
@echo ' make install Install dependencies.'
@echo ' make clean Clean the build directory.'
@echo ' make clean-node Remove Node dependencies.'
@echo ''
#############
# VARIABLES #
# Determine the Makefile filename:
THIS_FILE := $(lastword $(MAKEFILE_LIST))
# Determine the absolute path of the Makefile (see http://blog.jgc.org/2007/01/what-makefile-am-i-in.html):
THIS_DIR := $(dir $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
# Remove the trailing slash:
THIS_DIR := $(patsubst %/,%,$(THIS_DIR))
GREP ?= grep
NPM ?= npm
NODE ?= node
NODE_ENV ?= test
NODE_MODULES ?= $(THIS_DIR)/node_modules
TRAVIS ?= false
KERNEL ?= $(shell uname -s)
ifeq ($(KERNEL), Darwin)
OPEN ?= open
else
OPEN ?= xdg-open
endif
# NOTES #
NOTES ?= 'TODO|FIXME|WARNING|HACK|NOTE|OPTIMIZE'
# TAPE #
TAPE ?= $(NODE_MODULES)/.bin/tape
TAP_REPORTER ?= $(NODE_MODULES)/.bin/tap-spec
TAP_SUMMARY ?= $(NODE_MODULES)/.bin/tap-summary
# ISTANBUL #
REPORTS_DIR ?= $(THIS_DIR)/reports
ISTANBUL ?= $(NODE_MODULES)/.bin/istanbul
ISTANBUL_OUT ?= $(REPORTS_DIR)/coverage
ISTANBUL_REPORT ?= lcov
ISTANBUL_LCOV_INFO_PATH ?= $(ISTANBUL_OUT)/lcov.info
ISTANBUL_HTML_REPORT_PATH ?= $(ISTANBUL_OUT)/lcov-report/index.html
# CODECOV #
CODECOV ?= $(NODE_MODULES)/.bin/codecov
# BROWSERIFY #
BROWSERIFY ?= $(NODE_MODULES)/.bin/browserify
BROWSERIFY_PROXYQUIRE ?= $(NODE_MODULES)/proxyquire-universal
# TESTLING #
TESTLING ?= $(NODE_MODULES)/.bin/testling
TESTLING_DIR ?= $(THIS_DIR)/
# JSHINT #
JSHINT ?= $(NODE_MODULES)/.bin/jshint
JSHINT_REPORTER ?= $(NODE_MODULES)/jshint-stylish
# FILES #
SOURCE_DIR ?= $(THIS_DIR)
TESTS_DIR ?= test
EXAMPLES_DIR ?= examples
SOURCES_FILTER ?= .*/.*
TESTS_FILTER ?= .*/.*
EXAMPLES_FILTER ?= .*/.*
# On Mac OSX, in order to use `|` and other regular expression operators, we need to use enhanced regular expression syntax (-E); see https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man7/re_format.7.html#//apple_ref/doc/man/7/re_format.
ifeq ($(KERNEL), Darwin)
SOURCES ?= $(shell find -E $(SOURCE_DIR) \
-name '*.js' \
-regex "$(SOURCES_FILTER)" \
-not -name 'test*.js' \
-not -path "$(NODE_MODULES)/*" \
-not -path "**/$(EXAMPLES_DIR)/*" \
-not -path "$(REPORTS_DIR)/*" \
)
TESTS ?= $(shell find -E $(SOURCE_DIR) \
-name 'test*.js' \
-regex "$(TESTS_FILTER)" \
-not -path "$(NODE_MODULES)/*" \
)
EXAMPLES ?= $(shell find -E $(SOURCE_DIR) \
-name '*.js' \
-path "$(SOURCE_DIR)/**/$(EXAMPLES_DIR)/**" \
-regex "$(EXAMPLES_FILTER)" \
-not -path "$(NODE_MODULES)/*" \
)
else
SOURCES ?= $(shell find $(SOURCE_DIR) \
-name '*.js' \
-regextype posix-extended \
-regex "$(SOURCES_FILTER)" \
-not -name 'test*.js' \
-not -path "$(NODE_MODULES)/*" \
-not -path "**/$(EXAMPLES_DIR)/*" \
-not -path "$(REPORTS_DIR)/*" \
)
TESTS ?= $(shell find $(SOURCE_DIR) \
-name 'test*.js' \
-regextype posix-extended \
-regex "$(TESTS_FILTER)" \
-not -path "$(NODE_MODULES)/*" \
)
EXAMPLES ?= $(shell find $(SOURCE_DIR) \
-name '*.js' \
-path "$(SOURCE_DIR)/**/$(EXAMPLES_DIR)/**" \
-regextype posix-extended \
-regex "$(EXAMPLES_FILTER)" \
-not -path "$(NODE_MODULES)/*" \
)
endif
###########
# TARGETS #
# NOTES #
.PHONY: notes
notes:
$(GREP) -Ern $(NOTES) $(SOURCE_DIR) \
--exclude-dir "$(NODE_MODULES)/*" \
--exclude "$(THIS_FILE)" \
--exclude "$(THIS_DIR)/.*" \
--exclude "$(REPORTS_DIR)/*" \
--exclude TODO.md
# FILES #
.PHONY: list-sources list-examples list-tests
list-sources:
@printf '%s\n' $(SOURCES)
list-examples:
@printf '%s\n' $(EXAMPLES)
list-tests:
@printf '%s\n' $(TESTS)
# EXAMPLES #
.PHONY: examples
examples: node_modules
for file in $(EXAMPLES); do \
echo ""; \
echo "Running example: $$file"; \
$(NODE) $$file; \
done
# UNIT TESTS #
.PHONY: test test-local test-tape test-summary
test:
ifeq ($(TRAVIS), true)
@$(MAKE) -f $(THIS_FILE) test-ci
else
@$(MAKE) -f $(THIS_FILE) test-local
endif
test-local: test-tape
test-tape: node_modules
NODE_ENV=$(NODE_ENV) \
NODE_PATH=$(NODE_PATH_TEST) \
$(TAPE) \
$(TESTS) \
| $(TAP_REPORTER)
test-summary: node_modules
NODE_ENV=$(NODE_ENV) \
NODE_PATH=$(NODE_PATH_TEST) \
$(TAPE) \
$(TESTS) \
| $(TAP_SUMMARY)
# BROWSER TESTS #
.PHONY: test-browsers test-testling view-browser-tests view-testling
test-browsers: test-testling
test-testling: node_modules
NODE_ENV=$(NODE_ENV) \
NODE_PATH=$(NODE_PATH_TEST) \
$(BROWSERIFY) \
-p $(BROWSERIFY_PROXYQUIRE) \
$(TESTS) \
| $(TESTLING) \
| $(TAP_REPORTER)
view-browser-tests: view-testling
view-testling: node_modules
NODE_ENV=$(NODE_ENV) \
NODE_PATH=$(NODE_PATH_TEST) \
$(BROWSERIFY) \
-p $(BROWSERIFY_PROXYQUIRE) \
$(TESTS) \
| $(TESTLING) \
--x $(OPEN) \
| $(TAP_REPORTER)
# CODE COVERAGE #
.PHONY: test-cov test-istanbul-tape
test-cov: test-istanbul-tape
test-istanbul-tape: node_modules
NODE_ENV=$(NODE_ENV) \
NODE_PATH=$(NODE_PATH_TEST) \
$(ISTANBUL) cover \
--no-default-excludes \
-x 'node_modules/**' \
-x '**/test/**' \
-x '**/tests/**' \
-x 'reports/**' \
--dir $(ISTANBUL_OUT) \
--report $(ISTANBUL_REPORT) \
$(TAPE) -- \
$(TESTS)
# COVERAGE REPORT #
.PHONY: view-cov view-istanbul-report
view-cov: view-istanbul-report
view-istanbul-report:
$(OPEN) $(ISTANBUL_HTML_REPORT_PATH)
# CONTINUOUS INTEGRATION #
.PHONY: test-ci test-ci-browsers
.PHONY: coverage coverage-codecov
# test-ci: test-local test-ci-browsers
test-ci: test-local
test-ci-browsers: node_modules
xvfb-run make -f $(THIS_FILE) test-browsers
coverage: coverage-codecov
coverage-codecov: test-cov
$(NPM) install codecov
cat $(ISTANBUL_LCOV_INFO_PATH) | $(CODECOV)
# LINT #
.PHONY: lint lint-jshint
lint: lint-jshint
lint-jshint: node_modules
$(JSHINT) \
--reporter $(JSHINT_REPORTER) \
$(SOURCE_DIR)/
# NODE #
.PHONY: install clean-node
install: package.json
$(NPM) install
clean-node:
rm -rf $(NODE_MODULES)
# CLEAN #
.PHONY: clean
clean:
rm -rf build