-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
159 lines (138 loc) · 7.1 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
################################################################################
# CONFIGURATION ################################################################
################################################################################
### 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_DIR ?= ../testing-module-install
### JS/COFFEE ##################################################################
COFFEE_EXE ?= ./node_modules/.bin/coffee
NODE_EXE ?= node
COFFEE_COMPILE ?= $(COFFEE_EXE) -c
COFFEE_COMPILE_ARGS ?=
COFFEE_SRCS ?= $(wildcard lib/*.coffee)
COFFEE_TEST_SRCS ?= $(wildcard test/*.coffee)
COFFEE_JS ?= ${COFFEE_SRCS:.coffee=.js}
### MOCHA ######################################################################
MOCHA_EXE ?= ./node_modules/.bin/mocha
MOCHA_TESTS ?= $(wildcard test/test-*.coffee)
MOCHA_TEST_PATTERN ?=
MOCHA_TIMEOUT ?=-t 2000
MOCHA_TEST_ARGS ?= -R list --compilers coffee:coffee-script/register $(MOCHA_TIMEOUT) $(MOCHA_TEST_PATTERN)
# ### JSCOVERAGE #################################################################
# JSCOVERAGE_EXE ?= ./node_modules/.bin/node-jscoverage
# JSCOVERAGE_REPORT ?= docs/coverage.html
# JSCOVERAGE_TMP_DIR ?= ./jscov-tmp
# LIB_COV ?= lib-cov
# LIB ?= lib
# # MOCHA_COV_ARGS ?= -R html-cov --compilers coffee:coffee-script/register --globals "_\$$jscoverage"
# MOCHA_COV_ARGS ?= --require $(LIB_COV)/coffee-coverage-init.js --globals "_\$$jscoverage" --compilers coffee:coffee-script/register -R html-cov -t 20000
# 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 2000
### MARKDOWN ###################################################################
MARKDOWN_EXE ?= ./node_modules/.bin/marked
MARKDOWN_SRCS ?= $(shell find . -type f -name '*.md' | grep -v node_modules | grep -v module | grep -v common-dustjs-helpers-v.*)
MARKDOWN_HTML ?= ${MARKDOWN_SRCS:.md=.html}
# LITCOFFEE_SRCS ?= $(shell find . -type f -name '*.litcoffee' | grep -v node_modules | grep -v module)
# LITCOFFEE_HTML ?= ${LITCOFFEE_SRCS:.litcoffee=.html}
MARKDOWN_EXE_ARGS ?= -gfm
MARKDOWN_PREFIX ?= "<html><body>"
MARKDOWN_SUFFIX ?= "</body></html>"
################################################################################
# TARGETS ######################################################################
################################################################################
.SUFFIXES:;
.PHONY: all clean really-clean npm install clean-node-modules really-clean-node-modules test clean-test-module-install clean-module module test-module-install coverage clean-coverage docco markdown clean-docco clean-markdown docs clean-docs publish coffee litcoffee clean-litcoffee;
### ALL ########################################################################
all: test;
clean: clean-node-modules clean-test-module-install clean-module clean-coverage clean-docs clean-js;
really-clean: clean really-clean-node-modules;
### JS / COFFEE ################################################################
js: $(NODE_MODULES) $(COFFEE_JS)
coffee: js; # an alias
.SUFFIXES: .js .coffee
.coffee.js:
$(COFFEE_COMPILE) $(COFFEE_COMPILE_ARGS) $<
$(COFFEE_JS_OBJ): $(NODE_MODULES) $(COFFEE_SRCS)
clean-js:
rm -f $(COFFEE_JS)
### NPM ########################################################################
module: test coverage docs js
mkdir -p $(MODULE_DIR)
cp README.md $(MODULE_DIR)
cp LICENSE $(MODULE_DIR)
cp -r lib $(MODULE_DIR)
cp $(PACKAGE_JSON) $(MODULE_DIR)
mv module $(PACKAGE_DIR)
tar -czf $(PACKAGE_DIR).tgz $(PACKAGE_DIR)
test-module-install: clean-test-module-install module
mkdir -p ${TEST_MODULE_DIR}; cd ${TEST_MODULE_DIR}; npm install "$(CURDIR)/$(PACKAGE_DIR).tgz"; node -e "require('assert').ok(require('common-dustjs-helpers').exportTo !== null);" && echo "\n\033[1;32m It worked! \033[0m\n" && cd $(CURDIR) && rm -rf ${TEST_MODULE_DIR}
$(NODE_MODULES): $(PACKAGE_JSON)
$(NPM_EXE) prune
$(NPM_EXE) --silent 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
clean-node-modules:; $(NPM_EXE) prune
really-clean-node-modules:; rm -rf $(NODE_MODULES)
clean-test-module-install:; rm -rf ${TEST_MODULE_DIR}
clean-module:
rm -rf ${MODULE_DIR}
rm -rf $(PACKAGE_DIR)
rm -rf $(PACKAGE_DIR).tgz
publish: module test-module-install; $(NPM_EXE) publish $(PACKAGE_DIR).tgz
### MOCHA ######################################################################
test: test-mocha
test-mocha: $(NODE_MODULES) $(MOCHA_TESTS) $(COFFEE_SRCS) $(COFFEE_TEST_SRCS);
$(MOCHA_EXE) $(MOCHA_TEST_ARGS) $(MOCHA_TESTS)
clean-coverage:; rm -rf $(COVERAGE_TMP_DIR) $(LIB_COV) $(COVERAGE_REPORT)
coverage: $(COFFEE_SRCS) $(COFFEE_TEST_SRCS) $(MOCHA_TESTS) $(NODE_MODULES)
rm -rf $(COVERAGE_TMP_DIR)
rm -rf $(LIB_COV)
mkdir -p $(COVERAGE_TMP_DIR)
cp -r $(LIB)/* $(COVERAGE_TMP_DIR)/.
$(COVERAGE_EXE) $(COVERAGE_ARGS) $(COVERAGE_TMP_DIR) $(LIB_COV)
mkdir -p `dirname $(COVERAGE_REPORT)`
$(MOCHA_EXE) $(MOCHA_COV_ARGS) $(MOCHA_TESTS) > $(COVERAGE_REPORT)
rm -rf $(COVERAGE_TMP_DIR)
rm -rf $(LIB_COV)
### DOCS #######################################################################
docs: markdown litcoffee docco
.SUFFIXES: .html .md
.md.html:
(echo $(MARKDOWN_PREFIX) > $@) && ($(MARKDOWN_EXE) $(MARKDOWN_EXE_ARGS) $< >> $@) && (echo $(MARKDOWN_SUFFIX) >> $@)
$(MARKDOWN_HTML_OBJ): $(MARKDOWN_SRCS)
.SUFFIXES: .html .litcoffee
.litcoffee.html:
(echo $(MARKDOWN_PREFIX) > $@) && ($(MARKDOWN_EXE) $(MARKDOWN_EXE_ARGS) $< >> $@) && (echo $(MARKDOWN_SUFFIX) >> $@)
$(LITCOFFEE_HTML_OBJ): $(LITCOFFEE_SRCS)
markdown: $(MARKDOWN_HTML)
litcoffee: $(LITCOFFEE_HTML)
docco: $(COFFEE_SRCS) $(NODE_MODULES)
rm -rf docs/docco
mkdir -p docs
mv docs docs-temporarily-renamed-so-docco-doesnt-clobber-it
docco $(COFFEE_SRCS)
mv docs docs-temporarily-renamed-so-docco-doesnt-clobber-it/docco
mv docs-temporarily-renamed-so-docco-doesnt-clobber-it docs
clean-docs: clean-docco clean-markdown;
clean-docco:; rm -rf docs/docco
clean-markdown:; rm -rf $(MARKDOWN_HTML)
clean-litcoffee:; rm -rf $(LITCOFFEE_HTML)
################################################################################
# EOF ##########################################################################
################################################################################