forked from paularmstrong/swig
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
192 lines (159 loc) · 4.55 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
SHA := $(shell git rev-parse HEAD)
THIS_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
VERSION_REGEX = [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*[^\" ]*
VERSION := $(shell npm ls | grep "swig@" | grep -Eo "${VERSION_REGEX}" -m 1)
TMP = 'tmp'
REMOTE = origin
BRANCH = gh-pages
BIN = node_modules/.bin
PWD = $(shell pwd | sed -e 's/[\/&]/\\&/g')
all:
@echo "Installing packages"
@npm install --depth=100 --loglevel=error
@npm link &>/dev/null
@cp scripts/githooks/* .git/hooks/
@chmod -R +x .git/hooks/
.INTERMEDIATE version: \
browser/comments.js \
docs/index.json
version:
@sed -i.bak 's/${VERSION_REGEX}/${VERSION}/' lib/swig.js
@rm lib/swig.js.bak
browser/comments.js: FORCE
@sed -i.bak 's/v${VERSION_REGEX}/v${VERSION}/' $@
.SECONDARY dist/swig.js: \
browser/comments.js
.SECONDARY dist/swig.min.js: \
dist/swig.js
.INTERMEDIATE browser/test/tests.js: \
tests/comments.test.js \
tests/filters.test.js \
tests/tags.test.js \
tests/variables.test.js \
tests/tags/autoescape.test.js \
tests/tags/else.test.js \
tests/tags/filter.test.js \
tests/tags/for.test.js \
tests/tags/if.test.js \
tests/tags/macro.test.js \
tests/tags/raw.test.js \
tests/tags/set.test.js \
tests/tags/spaceless.test.js \
tests/basic.test.js
clean: FORCE
@rm -rf dist
@rm -rf ${TMP}
build: clean dist dist/swig.min.js
@echo "Built to ./dist/"
dist:
@mkdir -p $@
dist/swig.js:
@echo "Building $@..."
@cat $^ > $@
@${BIN}/browserify browser/index.js >> $@
dist/swig.min.js:
@echo "Building $@..."
@${BIN}/uglifyjs $^ --comments -c warnings=false -m --source-map dist/swig.js.map > $@
browser/test/tests.js:
@echo "Building $@..."
@cat $^ > tests/browser.js
@perl -pi -e 's/\.\.\/\.\.\/lib/\.\.\/lib/g' tests/browser.js
@${BIN}/browserify tests/browser.js > $@
@rm tests/browser.js
tests := $(shell find ./tests -name '*.test.js' ! -path "*node_modules/*")
reporter = dot
opts =
test:
@${BIN}/mocha --check-leaks --reporter ${reporter} ${opts} ${tests}
test-browser: FORCE clean browser/test/tests.js
@${BIN}/mocha-phantomjs browser/test/index.html --reporter ${reporter}
files := $(shell find . -name '*.js' ! -path "./node_modules/*" ! -path "./dist/*" ! -path "./browser*" ! -path "./docs*" ! -path "./tmp*")
lint:
@${BIN}/nodelint ${files} --config=scripts/config-lint.js
out = tests/coverage.html
cov-reporter = html-cov
coverage:
ifeq (${cov-reporter}, travis-cov)
@${BIN}/mocha ${opts} ${tests} --require blanket -R ${cov-reporter}
else
@${BIN}/mocha ${opts} ${tests} --require blanket -R ${cov-reporter} > ${out}
@sed -i .bak -e "s/${PWD}//g" ${out}
@rm ${out}.bak
@echo
@echo "Built Report to ${out}"
@echo
endif
docs/index.json: FORCE
@echo "Building $@..."
@sed -i.bak 's/v${VERSION_REGEX}/v${VERSION}/' $@
docs/docs.json: FORCE
@echo "Building $@..."
@sed -i.bak 's/v${VERSION_REGEX}/v${VERSION}/' $@
docs/coverage.html: FORCE
@echo "Building $@..."
@make coverage out=$@
docs/docs/api.json: FORCE
@echo "Building $@..."
@echo '{ "api": ' > $@
@${BIN}/jsdoc lib/swig.js -X >> $@
@echo '}' >> $@
docs/docs/filters.json: FORCE
@echo "Building $@..."
@echo '{ "filters": ' > $@
@${BIN}/jsdoc lib/filters.js -X >> $@
@echo '}' >> $@
docs/docs/tags.json: FORCE
@echo "Building $@..."
@echo '{ "tags": ' > $@
@${BIN}/jsdoc lib/tags/ -X >> $@
@echo '}' >> $@
docs/docs/loaders.json: FORCE
@echo "Building $@..."
@echo '{ "loaders": ' > $@
@${BIN}/jsdoc lib/loaders/ -X >> $@
@echo '}' >> $@
docs/docs/extending.json: FORCE
@echo "Building $@..."
@echo '{ "ext": ' > $@
@${BIN}/jsdoc lib/parser.js lib/lexer.js -X >> $@
@echo '}' >> $@
.SECONDARY build-docs: \
docs/index.json \
docs/docs.json
.INTERMDIATE build-docs: \
docs/docs/api.json \
docs/docs/filters.json \
docs/docs/tags.json \
docs/docs/extending.json \
docs/docs/loaders.json
build-docs: FORCE
@echo "Documentation built."
gh-pages: clean build build-docs
@mkdir -p ${TMP}/js
@mkdir -p docs/css
@rm -f docs/coverage.html
@${BIN}/lessc --yui-compress --include-path=docs/less docs/less/swig.less docs/css/swig.css
@${BIN}/still docs -o ${TMP} -i "layout" -i "json" -i "less" -v
@make coverage out=${TMP}/coverage.html
@cp dist/swig.* ${TMP}/js/
@git checkout ${BRANCH}
@cp -r ${TMP}/* ./
@rm -rf ${TMP}
ifeq (${THIS_BRANCH}, master)
@git add .
@git commit -n -am "Automated build from ${SHA}"
@git push ${REMOTE} ${BRANCH}
@git checkout ${THIS_BRANCH}
@git clean -f -d docs/
endif
port = 3000
docs: build build-docs
@${BIN}/still-server docs/ -p ${port} -o
FORCE:
.PHONY: all version \
build build-docs \
test test-browser lint coverage \
docs gh-pages