UNPKG

3.14 kBPlain TextView Raw
1
2# get Makefile directory name: http://stackoverflow.com/a/5982798/376773
3THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
4THIS_DIR:=$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd)
5
6# BIN directory
7BIN := $(THIS_DIR)/node_modules/.bin
8
9# Testing WEB APP port
10TESTAPP_DIR := webapp/tests
11TESTAPP_PORT := 3001
12
13# Files
14JS_FILES := $(wildcard index.js lib/*.js test/*.js)
15JS_TESTING_FILES := $(wildcard test/test*.js test-whitelist/test*.js)
16
17# applications
18NODE ?= node
19NPM ?= $(NODE) $(shell which npm)
20MOCHA ?= $(NODE) $(BIN)/mocha
21BABEL ?= $(NODE) $(BIN)/babel
22WEBPACK ?= $(NODE) $(BIN)/webpack
23
24standalone: dist/wpcom.js
25
26install: node_modules
27
28clean:
29 @rm -rf dist
30
31distclean: clean
32 @rm -rf node_modules
33
34dist: dist/lib dist/test
35 @mkdir -p $@
36
37dist/lib: dist/lib/util dist/lib/runtime
38 @mkdir -p $@
39
40dist/lib/util:
41 @mkdir -p $@
42
43dist/lib/runtime:
44 @mkdir -p $@
45
46dist/test:
47 @mkdir -p $@
48
49dist/wpcom.js: *.js dist lib/*.js
50 @$(WEBPACK) -p --config webpack.config.js
51
52babelify: dist
53 @$(BABEL) \
54 index.js \
55 --optional runtime \
56 --out-file dist/index.js
57 @$(BABEL) \
58 lib \
59 --optional runtime \
60 --out-dir dist/lib
61 @$(BABEL) \
62 lib/util \
63 --optional runtime \
64 --out-dir dist/lib/util
65 @$(BABEL) \
66 lib/runtime \
67 --optional runtime \
68 --out-dir dist/lib/runtime
69 cp -rf lib/runtime/*.json dist/lib/runtime
70
71node_modules:
72 @NODE_ENV= $(NPM) install
73 @touch node_modules
74
75lint: node_modules/eslint node_modules/babel-eslint
76 @$(BIN)/eslint $(JS_FILES)
77
78eslint: lint
79
80example-server:
81 cd examples/server/; $(NPM) install
82 $(NODE) examples/server/index.js
83
84test: babelify
85 @$(MOCHA) \
86 --compilers js:babel/register \
87 --timeout 120s \
88 --slow 3s \
89 --grep "$(filter-out $@,$(MAKECMDGOALS))" \
90 --bail \
91 --reporter spec
92
93test-all: babelify
94 @$(MOCHA) \
95 --compilers js:babel/register \
96 --timeout 120s \
97 --slow 3s \
98 --bail \
99 --reporter spec
100
101commit-dist: clean standalone babelify
102 git add dist/ -v
103 git commit -m "re-build dist/"
104
105publish: clean standalone
106 $(NPM) publish
107
108# testing client app
109test-app: babelify dist/test/testing-source.js
110 mkdir -p webapp/tests
111 cp test/fixture.json dist/test/
112 cp test/config.json dist/test/
113 cp test/util.js dist/test/
114 cp ./node_modules/mocha/mocha.js $(TESTAPP_DIR)
115 cp ./node_modules/mocha/mocha.css $(TESTAPP_DIR)
116 @$(WEBPACK) -p --config ./webpack.tests.config.js
117
118run-test-app: babelify test-app
119 cd $(TESTAPP_DIR); serve -p $(TESTAPP_PORT)
120
121dist/test/testing-source.js: ${JS_TESTING_FILES}
122 mkdir -p dist/test/
123 cat > $@ $^
124
125webapp:
126 @$(WEBPACK) -p --config webapp/webpack.config.js
127
128deploy: test-app webapp
129 mkdir -p tmp/
130 rm -rf tmp/*
131 mkdir -p tmp/tests
132 cp webapp/index.html tmp/
133 cp webapp/style.css tmp/
134 cp webapp/webapp-bundle.js tmp/
135 cp $(TESTAPP_DIR)/index.html tmp/tests
136 cp $(TESTAPP_DIR)/mocha.css tmp/tests
137 cp $(TESTAPP_DIR)/mocha.js tmp/tests
138 cp $(TESTAPP_DIR)/testing-bundle.js tmp/tests
139 git checkout gh-pages
140 cp -rf tmp/* .
141 git add ./ -v
142 git commit -m "built"
143 git push origin gh-pages
144 git checkout -
145
146.PHONY: standalone clean distclean babelify example-server test test-all publish node_modules lint eslint webapp