UNPKG

3.1 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
70node_modules:
71 @NODE_ENV= $(NPM) install
72 @touch node_modules
73
74lint: node_modules/eslint node_modules/babel-eslint
75 @$(BIN)/eslint $(JS_FILES)
76
77eslint: lint
78
79example-server:
80 cd examples/server/; $(NPM) install
81 $(NODE) examples/server/index.js
82
83test: babelify
84 @$(MOCHA) \
85 --compilers js:babel/register \
86 --timeout 120s \
87 --slow 3s \
88 --grep "$(filter-out $@,$(MAKECMDGOALS))" \
89 --bail \
90 --reporter spec
91
92test-all: babelify
93 @$(MOCHA) \
94 --compilers js:babel/register \
95 --timeout 120s \
96 --slow 3s \
97 --bail \
98 --reporter spec
99
100commit-dist: clean standalone babelify
101 git add dist/ -v
102 git commit -m "re-build dist/"
103
104publish: clean standalone
105 $(NPM) publish
106
107# testing client app
108test-app: babelify dist/test/testing-source.js
109 mkdir -p webapp/tests
110 cp test/fixture.json dist/test/
111 cp test/config.json dist/test/
112 cp test/util.js dist/test/
113 cp ./node_modules/mocha/mocha.js $(TESTAPP_DIR)
114 cp ./node_modules/mocha/mocha.css $(TESTAPP_DIR)
115 @$(WEBPACK) -p --config ./webpack.tests.config.js
116
117run-test-app: babelify test-app
118 cd $(TESTAPP_DIR); serve -p $(TESTAPP_PORT)
119
120dist/test/testing-source.js: ${JS_TESTING_FILES}
121 mkdir -p dist/test/
122 cat > $@ $^
123
124webapp:
125 @$(WEBPACK) -p --config webapp/webpack.config.js
126
127deploy: test-app webapp
128 mkdir -p tmp/
129 rm -rf tmp/*
130 mkdir -p tmp/tests
131 cp webapp/index.html tmp/
132 cp webapp/style.css tmp/
133 cp webapp/webapp-bundle.js tmp/
134 cp $(TESTAPP_DIR)/index.html tmp/tests
135 cp $(TESTAPP_DIR)/mocha.css tmp/tests
136 cp $(TESTAPP_DIR)/mocha.js tmp/tests
137 cp $(TESTAPP_DIR)/testing-bundle.js tmp/tests
138 git checkout gh-pages
139 cp -rf tmp/* .
140 git add ./ -v
141 git commit -m "built"
142 git push origin gh-pages
143 git checkout -
144
145.PHONY: standalone clean distclean babelify example-server test test-all publish node_modules lint eslint webapp