-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
298 lines (247 loc) · 12.4 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
#-------------------------------------------------------------------------------
# NOTE: Try `make help` for a list of popular targets
#-------------------------------------------------------------------------------
# CONFIGURATION
################################################################################
# COFFEE & NODE ################################################################
COFFEE_EXE ?= ./node_modules/.bin/coffee
NODE_EXE ?= node
COFFEE_COMPILE ?= $(COFFEE_EXE) -c
COFFEE_COMPILE_ARGS ?=
COFFEE_SRCS ?= $(wildcard lib/*.coffee *.coffee)
COFFEE_TEST_SRCS ?= $(wildcard test/*.coffee)
COFFEE_JS ?= ${COFFEE_SRCS:.coffee=.js}
COFFEE_TEST_JS ?= ${COFFEE_TEST_SRCS:.coffee=.js}
# NPM ##########################################################################
NPM_EXE ?= npm
PACKAGE_JSON ?= package.json
NODE_MODULES ?= node_modules
MODULE_DIR ?= module
NPM_ARGS ?= --silent
# PACKAGING ####################################################################
PACKAGE_VERSION ?= $(shell $(NODE_EXE) -e "console.log(require('./$(PACKAGE_JSON)').version)")
PACKAGE_NAME ?= $(shell $(NODE_EXE) -e "console.log(require('./$(PACKAGE_JSON)').name)")
TMP_PACKAGE_DIR ?= packaging-$(PACKAGE_NAME)-$(PACKAGE_VERSION)-tmp
PACKAGE_DIR ?= $(PACKAGE_NAME)-v$(PACKAGE_VERSION)
TEST_MODULE_INSTALL_DIR ?= ../testing-module-install
# MOCHA ########################################################################
MOCHA_EXE ?= ./node_modules/.bin/mocha
TEST ?= $(wildcard test/test-*.coffee)
MOCHA_TESTS ?= $(TEST)
MOCHA_TEST_PATTERN ?=
MOCHA_TIMEOUT ?=-t 2000
MOCHA_TEST_ARGS ?= -R list --compilers coffee:coffee-script/register $(MOCHA_TIMEOUT) $(MOCHA_TEST_PATTERN)
MOCHA_EXTRA_ARGS ?=
# COVERAGE #####################################################################
LIB ?= lib
LIB_COV ?= lib-cov
COVERAGE_REPORT ?= docs/coverage.html
COVERAGE_TMP_DIR ?= ./cov-tmp
COVERAGE_EXE ?= ./node_modules/.bin/coffeeCoverage
COVERAGE_ARGS ?= -e migration --initfile $(LIB_COV)/coffee-coverage-init.js
MOCHA_COV_ARGS ?= --require $(LIB_COV)/coffee-coverage-init.js --globals "_\$$jscoverage" --compilers coffee:coffee-script/register -R html-cov -t 30000
# MARKDOWN #####################################################################
MARKDOWN_TOC ?= ./node_modules/.bin/toc
MARKDOWN_SRCS ?= $(shell find . -type f -name '*.md' | grep -v node_modules | grep -v module | grep -v .hold | grep -v "inote-util-v.*")
MARKDOWN_TOCED ?= ${MARKDOWN_SRCS:.md=.md-toc}
MARKDOWN_PROCESSOR ?= node -e "var h=require('highlight.js'),m=require('8fold-marked'),c='';process.stdin.on('data',function(b){c+=b.toString();});process.stdin.on('end',function(){m.setOptions({gfm:true,highlight:function(x,l){if(l){return h.highlight(l,x).value;}else{return x;}}});console.log(m(c))});process.stdin.resume();"
MARKDOWN_HTML ?= ${MARKDOWN_TOCED:.md-toc=.html}
MARKDOWN_PREFIX ?= "<html><head><style>`cat docs/styles/markdown.css`</style><body>"
MARKDOWN_SUFFIX ?= "</body></html>"
LITCOFFEE_PROCESSOR ?= node -e "var h=require('highlight.js'),m=require('8fold-marked'),c='';process.stdin.on('data',function(b){c+=b.toString();});process.stdin.on('end',function(){m.setOptions({gfm:true,highlight:function(x){return h.highlight('coffee',x).value;}});console.log(m(c))});process.stdin.resume();"
LITCOFFEE_SRCS ?= $(shell find . -type f -name '*.litcoffee' | grep -v node_modules | grep -v module | grep -v .hold)
LITCOFFEE_HTML ?= ${LITCOFFEE_SRCS:.litcoffee=.html}
LITCOFFEE_TOCED ?= ${LITCOFFEE_SRCS:.litcoffee=.md-toc}
# OTHER ########################################################################
DOCCO_EXE ?= ./node_modules/.bin/docco
################################################################################
# META-TARGETS AND SIMILAR
# `.SUFFIXES` - reset suffixes in case any were previously defined
.SUFFIXES:
# `.PHONY` - make targets that aren't actually files
.PHONY: all coffee clean clean-coverage clean-docco clean-docs clean-js clean-markdown clean-module clean-node-modules clean-test-module-install coverage docco docs fully-clean-node-modules js markdown module targets test test-module-install todo
# `all` - the default target
all: help
# `targets` - list targets that are not likely to be "meta" targets like .PHONY or .SUFFIXES
targets:
@grep -E "^[^ #.$$]+:( |$$)" Makefile | sort | cut -d ":" -f 1
# `todo` - list todo and related comments found in source files
todo:
@grep -C 0 --exclude-dir=node_modules --exclude-dir=.git --exclude=#*# --exclude=.#* --exclude=*.html --exclude=Makefile -IrHE "(TODO)|(FIXME)|(XXX)" *
help:
@echo ""
@echo "--------------------------------------------------------------------------------"
@echo "HERE ARE SOME POPULAR AND USEFUL TARGETS IN THIS MAKEFILE."
@echo "--------------------------------------------------------------------------------"
@echo ""
@echo "SET UP"
@echo " install - install npm dependencies (i.e., 'npm install')"
@echo " (also aliased as 'npm' and 'node_modules')"
@echo ""
@echo "AUTOMATED TESTS"
@echo " test - run the unit-test suite"
@echo " coverage - generate a unit-test coverage report"
@echo ""
@echo "DOCUMENTATION"
@echo " markdown - generate HTML versions of various *.md and *.litcoffee files"
@echo " docco - generate annotated source code view using docco"
@echo " docs - generate all of the above"
@echo ""
@echo "BUILD"
@echo " coffee - generate JavaScript files from CoffeeScript files"
@echo " module - create a packaged npm module for deployment"
@echo " test-module-install"
@echo " - create a packaged npm module for deployment and then"
@echo " validate that the module can be installed"
@echo ""
@echo "CLEAN UP"
@echo " clean - remove generated files and directories (except node_modules)"
@echo " really-clean - truly remove all generated files and directories"
@echo ""
@echo "OTHER"
@echo " todo - search source code for TODO items"
@echo " targets - generate a list of most available make targets"
@echo " help - this listing"
@echo ""
@echo "--------------------------------------------------------------------------------"
@echo ""
################################################################################
# CLEAN UP TARGETS
clean: _clean_msg clean-coverage clean-docco clean-docs clean-js clean-module clean-test-module-install clean-node-modules
_clean_msg:
@echo "\x1b[1m==== REMOVING GENERATED FILES ====\x1b[0m"
clean-test-module-install:
@rm -rf $(TEST_MODULE_INSTALL_DIR)
clean-module:
@rm -rf $(MODULE_DIR)
@rm -rf $(PACKAGE_DIR)
@rm -rf $(PACKAGE_DIR).tgz
clean-node-modules:
@echo "\x1b[1mPruning node_modules\x1b[0m"
@($(NPM_EXE) $(NPM_ARGS) prune)
really-clean: clean really-clean-node-modules
really-clean-node-modules: # deletes rather that simply pruning node_modules
@echo "\x1b[1mDeleting node_modules\x1b[0m"
@rm -rf $(NODE_MODULES)
clean-js:
@echo "\x1b[1mDeleting *.js\x1b[0m"
@rm -f $(COFFEE_JS) $(COFFEE_TEST_JS)
clean-coverage:
@rm -rf $(COVERAGE_TMP_DIR)
@rm -rf $(LIB_COV)
@rm -f $(COVERAGE_REPORT)
clean-docs: clean-markdown clean-docco
clean-docco:
@rm -rf docs/docco
clean-markdown:
@rm -rf $(MARKDOWN_HTML)
################################################################################
# NPM TARGETS
module: clean-module js test
@echo "\x1b[1m==== BUILDING NPM MODULE ====\x1b[0m"
@mkdir -p $(MODULE_DIR)
@cp -r lib $(MODULE_DIR)
@cp -r data $(MODULE_DIR)
@cp $(PACKAGE_JSON) $(MODULE_DIR)
@cp LICENSE.txt $(MODULE_DIR)
@cp README.md $(MODULE_DIR)
@mv module $(PACKAGE_DIR)
@tar -czf $(PACKAGE_DIR).tgz $(PACKAGE_DIR)
test-module-install: clean-test-module-install js test docs module $(PACKAGE_DIR).tgz
@echo "\x1b[1m==== TESTING DEPLOYMENT OF NPM MODULE ====\x1b[0m"
@(mkdir -p $(TEST_MODULE_INSTALL_DIR); cd $(TEST_MODULE_INSTALL_DIR); npm install "$(CURDIR)/$(PACKAGE_DIR).tgz"; node -e "require('assert').ok(require('inote-util').Util);" && cd $(CURDIR) && rm -rf $(TEST_MODULE_INSTALL_DIR) && echo "\n\nIT WORKED!\n\n")
$(NODE_MODULES): $(PACKAGE_JSON)
@($(NPM_EXE) $(NPM_ARGS) prune)
@($(NPM_EXE) $(NPM_ARGS) install)
@touch $(NODE_MODULES) # touch the module dir so it looks younger than `package.json`
npm: $(NODE_MODULES) # an alias
install: $(NODE_MODULES) # an alias
################################################################################
# COFFEE TARGETS
coffee: $(NODE_MODULES)
@rm -rf $(LIB_COV)
js: _js_msg coffee $(COFFEE_JS) $(COFFEE_TEST_JS)
_js_msg:
@echo "\x1b[1m==== BUILDING JS FILES ====\x1b[0m"
.SUFFIXES: .js .coffee
.coffee.js:
@($(COFFEE_COMPILE) $(COFFEE_COMPILE_ARGS) $<)
$(COFFEE_JS_OBJ): $(NODE_MODULES) $(COFFEE_SRCS) $(COFFEE_TEST_SRCS)
################################################################################
# TEST TARGETS
test: $(MOCHA_TESTS) $(NODE_MODULES)
@echo "\x1b[1m==== RUNNING UNIT TESTS ====\x1b[0m"
($(MOCHA_EXE) $(MOCHA_TEST_ARGS) ${MOCHA_EXTRA_ARGS} $(MOCHA_TESTS))
test-watch: $(MOCHA_TESTS) $(NODE_MODULES)
@($(MOCHA_EXE) --watch $(MOCHA_TEST_ARGS) ${MOCHA_EXTRA_ARGS} $(MOCHA_TESTS))
define COVERAGE_SUMMARY
stew = new (require("stew-select")).Stew()
html = require("fs").readFileSync("$(COVERAGE_REPORT)").toString()
pad = require("./lib/string-util").StringUtil.lpad
stew.select_first html, "#stats", (err,node)->
inner = stew.dom_util.inner_html(node)
stew.select inner, "div", (err,nodes)->
nodes = nodes.map (x)->stew.dom_util.to_text(x)
console.log ""
console.log "\x1b[1mTEST COVERAGE SUMMARY\x1b[0m"
console.log "\x1b[1m Coverage: \x1b[0m",pad(nodes[0] ? -1 , 5)
console.log "\x1b[1m SLOC: \x1b[0m",pad(nodes[1] ? -1 , 5)
console.log "\x1b[1m Hits: \x1b[0m",pad(nodes[2] ? -1 , 5)
console.log "\x1b[1m Misses: \x1b[0m",pad(nodes[3] ? -1 , 5)
console.log ""
endef
export COVERAGE_SUMMARY
coverage: $(COFFEE_SRCS) $(COFFEE_TEST_SRCS) $(MOCHA_TESTS) $(NODE_MODULES)
@echo "\x1b[1m==== RUNNING TEST COVERAGE REPORT ====\x1b[0m"
@rm -rf $(COVERAGE_TMP_DIR)
@rm -rf $(LIB_COV)
@mkdir -p $(COVERAGE_TMP_DIR)
@cp -r $(LIB)/* $(COVERAGE_TMP_DIR)/.
@echo "\x1b[1mAnnotating Source Code\x1b[0m"
$(COVERAGE_EXE) $(COVERAGE_ARGS) $(COVERAGE_TMP_DIR) $(LIB_COV)
@mkdir -p `dirname $(COVERAGE_REPORT)`
@echo "\x1b[1mRunning Unit Tests\x1b[0m"
($(MOCHA_EXE) $(MOCHA_COV_ARGS) $(MOCHA_TESTS) > $(COVERAGE_REPORT) 2>/dev/null) || true
@echo "\x1b[1mComputing Summary\x1b[0m"
@$(COFFEE_EXE) -e "$$COVERAGE_SUMMARY"
@rm -rf $(COVERAGE_TMP_DIR)
@rm -rf $(LIB_COV)
@echo "Detailed coverage report generated at \x1b[1m$(COVERAGE_REPORT)\x1b[0m."
@echo "USE \x1b[1mopen $(COVERAGE_REPORT)\x1b[0m TO OPEN (ON OSX)"
################################################################################
# MARKDOWN & OTHER DOC TARGETS
docs: markdown docco
.SUFFIXES: .md-toc .md
.md.md-toc:
@cp "$<" "$@"
@($(MARKDOWN_TOC) "$@")
$(MARKDOWN_TOCCED_OBJ): $(MARKDOWN_SRCS)
# (echo $(MARKDOWN_PREFIX) > $@) && ($(MARKDOWN_PROCESSOR) $(MARKDOWN_PROCESSOR_ARGS) $< | sed "s/<!-- toc -->/<div id=TofC>/" | sed "s/<!-- toc stop -->/<\/div>/" >> $@) && (echo $(MARKDOWN_SUFFIX) >> $@)
.SUFFIXES: .html .md-toc
.md-toc.html:
@((echo $(MARKDOWN_PREFIX) > $@) && (cat "$<" | $(MARKDOWN_PROCESSOR) | sed "s/<!-- toc -->/<div id=TofC>/" | sed "s/<!-- toc stop -->/<div style=\"font-size: 0.9em; text-align: right\"><a href=\".\" >[up]<\/a> <a href=\"javascript:back(-1)\">[back]<\/a><\/div><\/div>/" >> $@) && (echo $(MARKDOWN_SUFFIX) >> $@))
$(MARKDOWN_HTML_OBJ): $(MARKDOWN_TOCCED_OBJ)
.SUFFIXES: .litcoffee-toc .litcoffee
.litcoffee.litcoffee-toc:
@cp "$<" "$@"
@($(MARKDOWN_TOC) "$@")
$(LITCOFFEE_TOCCED_OBJ): $(LITCOFFEE_SRCS)
.SUFFIXES: .html .litcoffee-toc
.litcoffee-toc.html:
(echo $(MARKDOWN_PREFIX) > $@) && (cat "$<" | $(LITCOFFEE_PROCESSOR) | sed "s/<!-- toc -->/<div id=TofC>/" | sed "s/<!-- toc stop -->/<div style=\"font-size: 0.9em; text-align: right\"><a href=\".\" >[up]<\/a> <a href=\"javascript:back(-1)\">[back]<\/a><\/div><\/div>/" >> $@) && (echo $(MARKDOWN_SUFFIX) >> $@)
$(LITCOFFEE_HTML_OBJ): $(LITCOFFEE_TOCCED_OBJ) docs/styles/markdown.css
$(MARKDOWN_HTML): docs/styles/markdown.css
$(LITCOFFEE_HTML): docs/styles/markdown.css
markdown: $(MARKDOWN_HTML) $(LITCOFFEE_HTML) $(NODE_MODULES)
html: markdown
docco: $(COFFEE_SRCS) $(NODE_MODULES)
@echo "\x1b[1m==== GENERATING ANNOTATED SOURCE CODE ====\x1b[0m"
@rm -rf docs/docco
@mkdir -p docs
@mv docs docs-temporarily-renamed-so-docco-doesnt-clobber-it
@($(DOCCO_EXE) $(COFFEE_SRCS))
@mv docs docs-temporarily-renamed-so-docco-doesnt-clobber-it/docco
@mv docs-temporarily-renamed-so-docco-doesnt-clobber-it docs
.SUFFIXES: .coffee
.coffee:
@($(COFFEE_EXE) $< > $@)