UNPKG

8.45 kBPlain TextView Raw
1PACKAGE = nodeunit
2NODEJS = $(if $(shell test -f /usr/bin/nodejs && echo "true"),nodejs,node)
3
4PREFIX ?= /usr/local
5BINDIR ?= $(PREFIX)/bin
6DATADIR ?= $(PREFIX)/share
7MANDIR ?= $(PREFIX)/share/man
8LIBDIR ?= $(PREFIX)/lib
9NODEJSLIBDIR ?= $(LIBDIR)/$(NODEJS)
10
11BUILDDIR = dist
12
13DOCS = $(shell find doc -name '*.md' \
14 |sed 's|.md|.1|g' \
15 |sed 's|doc/|man1/|g' \
16 )
17
18
19$(shell if [ ! -d $(BUILDDIR) ]; then mkdir $(BUILDDIR); fi)
20
21all: build doc
22
23browser:
24 # super hacky build script for browser version!
25 mkdir -p $(BUILDDIR)/browser
26 rm -rf $(BUILDDIR)/browser/*
27 # build browser version of nodeunit.js
28 cat share/license.js >> $(BUILDDIR)/browser/nodeunit.js
29 echo "nodeunit = (function(){" >> $(BUILDDIR)/browser/nodeunit.js
30 cat deps/json2.js >> $(BUILDDIR)/browser/nodeunit.js
31 # make assert global
32 echo "var assert = this.assert = {};" >> $(BUILDDIR)/browser/nodeunit.js
33 echo "var types = {};" >> $(BUILDDIR)/browser/nodeunit.js
34 echo "var core = {};" >> $(BUILDDIR)/browser/nodeunit.js
35 echo "var nodeunit = {};" >> $(BUILDDIR)/browser/nodeunit.js
36 echo "var reporter = {};" >> $(BUILDDIR)/browser/nodeunit.js
37 cat deps/async.js >> $(BUILDDIR)/browser/nodeunit.js
38 echo "(function(exports){" >> $(BUILDDIR)/browser/nodeunit.js
39 cat lib/assert.js >> $(BUILDDIR)/browser/nodeunit.js
40 echo "})(assert);" >> $(BUILDDIR)/browser/nodeunit.js
41 echo "(function(exports){" >> $(BUILDDIR)/browser/nodeunit.js
42 cat lib/types.js >> $(BUILDDIR)/browser/nodeunit.js
43 echo "})(types);" >> $(BUILDDIR)/browser/nodeunit.js
44 echo "(function(exports){" >> $(BUILDDIR)/browser/nodeunit.js
45 cat lib/core.js >> $(BUILDDIR)/browser/nodeunit.js
46 echo "})(core);" >> $(BUILDDIR)/browser/nodeunit.js
47 echo "(function(exports){" >> $(BUILDDIR)/browser/nodeunit.js
48 cat lib/reporters/browser.js >> $(BUILDDIR)/browser/nodeunit.js
49 echo "})(reporter);" >> $(BUILDDIR)/browser/nodeunit.js
50 echo "nodeunit = core;" >> $(BUILDDIR)/browser/nodeunit.js
51 echo "nodeunit.assert = assert;" >> $(BUILDDIR)/browser/nodeunit.js
52 echo "nodeunit.reporter = reporter;" >> $(BUILDDIR)/browser/nodeunit.js
53 echo "nodeunit.run = reporter.run;" >> $(BUILDDIR)/browser/nodeunit.js
54 echo "return nodeunit; })();" >> $(BUILDDIR)/browser/nodeunit.js
55 cp $(BUILDDIR)/browser/nodeunit.js $(BUILDDIR)/browser/.nodeunit.js
56 sed "/\@REMOVE_LINE_FOR_BROWSER/d" <$(BUILDDIR)/browser/.nodeunit.js > $(BUILDDIR)/browser/nodeunit.js
57 rm $(BUILDDIR)/browser/.nodeunit.js
58 # copy nodeunit.css
59 cp share/nodeunit.css $(BUILDDIR)/browser/nodeunit.css
60 # create nodeunit.min.js
61 node_modules/uglify-js/bin/uglifyjs $(BUILDDIR)/browser/nodeunit.js > $(BUILDDIR)/browser/nodeunit.min.js
62 # create test scripts
63 mkdir -p $(BUILDDIR)/browser/test
64 cp test/test.html $(BUILDDIR)/browser/test/test.html
65 # test-base.js
66 echo "(function (exports) {" > $(BUILDDIR)/browser/test/test-base.js
67 cat test/test-base.js >> $(BUILDDIR)/browser/test/test-base.js
68 echo "})(this.test_base = {});" >> $(BUILDDIR)/browser/test/test-base.js
69 cp $(BUILDDIR)/browser/test/test-base.js $(BUILDDIR)/browser/.test-base.js
70 sed "/\@REMOVE_LINE_FOR_BROWSER/d" <$(BUILDDIR)/browser/.test-base.js > $(BUILDDIR)/browser/test/test-base.js
71 rm $(BUILDDIR)/browser/.test-base.js
72 # test-runmodule.js
73 echo "(function (exports) {" > $(BUILDDIR)/browser/test/test-runmodule.js
74 cat test/test-runmodule.js >> $(BUILDDIR)/browser/test/test-runmodule.js
75 echo "})(this.test_runmodule = {});" >> $(BUILDDIR)/browser/test/test-runmodule.js
76 cp $(BUILDDIR)/browser/test/test-runmodule.js $(BUILDDIR)/browser/.test-runmodule.js
77 sed "/\@REMOVE_LINE_FOR_BROWSER/d" <$(BUILDDIR)/browser/.test-runmodule.js > $(BUILDDIR)/browser/test/test-runmodule.js
78 rm $(BUILDDIR)/browser/.test-runmodule.js
79 # test-runtest.js
80 echo "(function (exports) {" > $(BUILDDIR)/browser/test/test-runtest.js
81 cat test/test-runtest.js >> $(BUILDDIR)/browser/test/test-runtest.js
82 echo "})(this.test_runtest = {});" >> $(BUILDDIR)/browser/test/test-runtest.js
83 cp $(BUILDDIR)/browser/test/test-runtest.js $(BUILDDIR)/browser/.test-runtest.js
84 sed "/\@REMOVE_LINE_FOR_BROWSER/d" <$(BUILDDIR)/browser/.test-runtest.js > $(BUILDDIR)/browser/test/test-runtest.js
85 rm $(BUILDDIR)/browser/.test-runtest.js
86 # test-testcase.js
87 echo "(function (exports) {" > $(BUILDDIR)/browser/test/test-testcase.js
88 cat test/test-testcase.js >> $(BUILDDIR)/browser/test/test-testcase.js
89 echo "})(this.test_testcase = {});" >> $(BUILDDIR)/browser/test/test-testcase.js
90 cp $(BUILDDIR)/browser/test/test-testcase.js $(BUILDDIR)/browser/.test-testcase.js
91 sed "/\@REMOVE_LINE_FOR_BROWSER/d" <$(BUILDDIR)/browser/.test-testcase.js > $(BUILDDIR)/browser/test/test-testcase.js
92 rm $(BUILDDIR)/browser/.test-testcase.js
93 # test-testcase-legacy.js
94 echo "(function (exports) {" > $(BUILDDIR)/browser/test/test-testcase-legacy.js
95 cat test/test-testcase-legacy.js >> $(BUILDDIR)/browser/test/test-testcase-legacy.js
96 echo "})(this.test_testcase_legacy = {});" >> $(BUILDDIR)/browser/test/test-testcase-legacy.js
97 cp $(BUILDDIR)/browser/test/test-testcase-legacy.js $(BUILDDIR)/browser/.test-testcase-legacy.js
98 sed "/\@REMOVE_LINE_FOR_BROWSER/d" <$(BUILDDIR)/browser/.test-testcase-legacy.js > $(BUILDDIR)/browser/test/test-testcase-legacy.js
99 rm $(BUILDDIR)/browser/.test-testcase-legacy.js
100 # copy nodeunit.js to dist/browser/test to make it easier for me to host and
101 # run on windows VMs with IE
102 cp $(BUILDDIR)/browser/nodeunit.js $(BUILDDIR)/browser/test/nodeunit.js
103 cp $(BUILDDIR)/browser/nodeunit.css $(BUILDDIR)/browser/test/nodeunit.css
104
105commonjs:
106 # super hacky build script for browser commonjs version!
107 ##### make commonjs browser module ######
108 mkdir -p $(BUILDDIR)/commonjs
109 rm -rf $(BUILDDIR)/commonjs/*
110 mkdir -p $(BUILDDIR)/commonjs/deps
111 cp deps/json2.js $(BUILDDIR)/commonjs/deps
112 cp deps/async.js $(BUILDDIR)/commonjs/deps
113 echo "var async = require('async');" >> $(BUILDDIR)/commonjs/nodeunit.js
114 echo "var assert = {};" >> $(BUILDDIR)/commonjs/nodeunit.js
115 echo "var types = {};" >> $(BUILDDIR)/commonjs/nodeunit.js
116 echo "var core = {};" >> $(BUILDDIR)/commonjs/nodeunit.js
117 echo "var nodeunit = {};" >> $(BUILDDIR)/commonjs/nodeunit.js
118 echo "var reporter = {};" >> $(BUILDDIR)/commonjs/nodeunit.js
119 echo "(function(exports){" >> $(BUILDDIR)/commonjs/nodeunit.js
120 cat lib/assert.js >> $(BUILDDIR)/commonjs/nodeunit.js
121 echo "})(assert);" >> $(BUILDDIR)/commonjs/nodeunit.js
122 echo "(function(exports){" >> $(BUILDDIR)/commonjs/nodeunit.js
123 cat lib/types.js >> $(BUILDDIR)/commonjs/nodeunit.js
124 echo "})(types);" >> $(BUILDDIR)/commonjs/nodeunit.js
125 echo "(function(exports){" >> $(BUILDDIR)/commonjs/nodeunit.js
126 cat lib/core.js >> $(BUILDDIR)/commonjs/nodeunit.js
127 echo "})(core);" >> $(BUILDDIR)/commonjs/nodeunit.js
128 echo "module.exports = core;" >> $(BUILDDIR)/commonjs/nodeunit.js
129 echo "(function(exports, nodeunit){" >> $(BUILDDIR)/commonjs/nodeunit.js
130 cat lib/reporters/browser.js >> $(BUILDDIR)/commonjs/nodeunit.js
131 echo "})(reporter, module.exports);" >> $(BUILDDIR)/commonjs/nodeunit.js
132 echo "module.exports.assert = assert;" >> $(BUILDDIR)/commonjs/nodeunit.js
133 echo "module.exports.reporter = reporter;" >> $(BUILDDIR)/commonjs/nodeunit.js
134 echo "module.exports.run = reporter.run;" >> $(BUILDDIR)/commonjs/nodeunit.js
135 sed -i "/\@REMOVE_LINE_FOR_BROWSER/d" $(BUILDDIR)/commonjs/nodeunit.js
136 sed -i "/\@REMOVE_LINE_FOR_COMMONJS/d" $(BUILDDIR)/commonjs/nodeunit.js
137 ##### end of commonjs browser module #####
138
139build: stamp-build
140
141stamp-build: $(wildcard deps/* lib/*.js)
142 touch $@;
143 mkdir -p $(BUILDDIR)/nodeunit
144 cp -R bin node_modules deps index.js lib package.json share $(BUILDDIR)/nodeunit
145 printf '#!/bin/sh\n$(NODEJS) $(NODEJSLIBDIR)/$(PACKAGE)/bin/nodeunit $$@' > $(BUILDDIR)/nodeunit.sh
146
147test:
148 $(NODEJS) ./bin/nodeunit test
149
150install: build
151 install -d $(NODEJSLIBDIR)
152 cp -a $(BUILDDIR)/nodeunit $(NODEJSLIBDIR)
153 install -m 0755 $(BUILDDIR)/nodeunit.sh $(BINDIR)/nodeunit
154 install -d $(MANDIR)/man1/
155 cp -a man1/nodeunit.1 $(MANDIR)/man1/
156
157uninstall:
158 rm -rf $(NODEJSLIBDIR)/nodeunit $(NODEJSLIBDIR)/nodeunit.js $(BINDIR)/nodeunit
159 rm -rf $(MANDIR)/man1/nodeunit.1
160
161clean:
162 rm -rf $(BUILDDIR) stamp-build
163
164lint:
165 nodelint --config nodelint.cfg ./index.js ./bin/nodeunit ./bin/nodeunit.json ./lib/*.js ./lib/reporters/*.js ./test/*.js
166
167doc: man1 $(DOCS)
168 @true
169
170man1:
171 @if ! test -d man1 ; then mkdir -p man1 ; fi
172
173# use `npm install ronn` for this to work.
174man1/%.1: doc/%.md
175 ronn --roff $< > $@
176
177.PHONY: browser test install uninstall build all