1 |
|
2 | # get Makefile directory name: http://stackoverflow.com/a/5982798/376773
|
3 | THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
|
4 | THIS_DIR:=$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd)
|
5 |
|
6 | # BIN directory
|
7 | BIN := $(THIS_DIR)/node_modules/.bin
|
8 |
|
9 | # Testing WEB APP port
|
10 | TESTAPP_DIR := webapp/tests
|
11 | TESTAPP_PORT := 3001
|
12 |
|
13 | # Files
|
14 | JS_FILES := $(wildcard index.js lib/*.js test/*.js)
|
15 | JS_TESTING_FILES := $(wildcard test/test*.js test-whitelist/test*.js)
|
16 |
|
17 | # applications
|
18 | NODE ?= node
|
19 | NPM ?= $(NODE) $(shell which npm)
|
20 | MOCHA ?= $(NODE) $(BIN)/mocha
|
21 | BABEL ?= $(NODE) $(BIN)/babel
|
22 | WEBPACK ?= $(NODE) $(BIN)/webpack
|
23 |
|
24 | standalone: dist/wpcom.js
|
25 |
|
26 | install: node_modules
|
27 |
|
28 | clean:
|
29 | @rm -rf dist
|
30 |
|
31 | distclean: clean
|
32 | @rm -rf node_modules
|
33 |
|
34 | dist: dist/lib dist/test
|
35 | @mkdir -p $@
|
36 |
|
37 | dist/lib: dist/lib/util dist/lib/runtime
|
38 | @mkdir -p $@
|
39 |
|
40 | dist/lib/util:
|
41 | @mkdir -p $@
|
42 |
|
43 | dist/lib/runtime:
|
44 | @mkdir -p $@
|
45 |
|
46 | dist/test:
|
47 | @mkdir -p $@
|
48 |
|
49 | dist/wpcom.js: *.js dist lib/*.js
|
50 | @$(WEBPACK) -p --config webpack.config.js
|
51 |
|
52 | babelify: 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 |
|
70 | node_modules:
|
71 | @NODE_ENV= $(NPM) install
|
72 | @touch node_modules
|
73 |
|
74 | lint: node_modules/eslint node_modules/babel-eslint
|
75 | @$(BIN)/eslint $(JS_FILES)
|
76 |
|
77 | eslint: lint
|
78 |
|
79 | example-server:
|
80 | cd examples/server/; $(NPM) install
|
81 | $(NODE) examples/server/index.js
|
82 |
|
83 | test: 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 |
|
92 | test-all: babelify
|
93 | @$(MOCHA) \
|
94 | --compilers js:babel/register \
|
95 | --timeout 120s \
|
96 | --slow 3s \
|
97 | --bail \
|
98 | --reporter spec
|
99 |
|
100 | commit-dist: clean standalone babelify
|
101 | git add dist/ -v
|
102 | git commit -m "re-build dist/"
|
103 |
|
104 | publish: clean standalone
|
105 | $(NPM) publish
|
106 |
|
107 | # testing client app
|
108 | test-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 |
|
117 | run-test-app: babelify test-app
|
118 | cd $(TESTAPP_DIR); serve -p $(TESTAPP_PORT)
|
119 |
|
120 | dist/test/testing-source.js: ${JS_TESTING_FILES}
|
121 | mkdir -p dist/test/
|
122 | cat > $@ $^
|
123 |
|
124 | webapp:
|
125 | @$(WEBPACK) -p --config webapp/webpack.config.js
|
126 |
|
127 | deploy: 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
|