forked from Khan/perseus
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Makefile
166 lines (137 loc) · 5.87 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
.PHONY: help build serve server server-offline all subperseus forcesubperseus webapp-put install clean lint test jest
PORT=9000
WEBAPP=../webapp
IOS=../iOS
SUPPRESSINSTALL=FALSE
API_VERSION_MAJOR:=$(shell node node/echo-major-api-version.js)
PERSEUS_BUILD_JS=build/perseus-$(API_VERSION_MAJOR).js
PERSEUS_BUILD_CSS=build/perseus-$(API_VERSION_MAJOR).css
PERSEUS_NODE_BUILD_JS=build/node-perseus.js
PERSEUS_VERSION_FILE=build/perseus-$(API_VERSION_MAJOR)-item-version.js
help:
@echo "make server PORT=9000 # runs the perseus server"
@echo "make server-offline PORT=9000 # runs the perseus server"
@echo "make build # compiles into $(PERSEUS_BUILD_JS) and $(PERSEUS_BUILD_CSS)"
@echo "make subperseus # build perseus into webapp"
@echo "make clean # delete all compilation artifacts"
@echo "make test # run all tests"
@echo "# NOTE: you can append SUPPRESSINSTALL=TRUE to avoid running npm install. Useful if you temporarily have no internet."
build: $(PERSEUS_BUILD_JS) $(PERSEUS_NODE_BUILD_JS) $(PERSEUS_BUILD_CSS) $(PERSEUS_VERSION_FILE)
$(PERSEUS_BUILD_JS): install
mkdir -p build
./node_modules/.bin/webpack
echo '/*! Perseus | http://github.com/Khan/perseus */' > $(PERSEUS_BUILD_JS)
echo "// commit `git rev-parse HEAD`" >> $(PERSEUS_BUILD_JS)
echo "// branch `git rev-parse --abbrev-ref HEAD`" >> $(PERSEUS_BUILD_JS)
cat build/perseus.js >> $(PERSEUS_BUILD_JS)
$(PERSEUS_NODE_BUILD_JS): install
mkdir -p build
./node_modules/.bin/webpack --config webpack.config.node-perseus.js
mv build/node-perseus.js build/node-perseus.js.tmp
echo '/*! Nodeified Perseus | http://github.com/Khan/perseus */' > $(PERSEUS_NODE_BUILD_JS)
echo "// commit `git rev-parse HEAD`" >> $(PERSEUS_NODE_BUILD_JS)
echo "// branch `git rev-parse --abbrev-ref HEAD`" >> $(PERSEUS_NODE_BUILD_JS)
cat build/node-perseus.js.tmp >> $(PERSEUS_NODE_BUILD_JS)
rm build/node-perseus.js.tmp
$(PERSEUS_BUILD_CSS): install
mkdir -p build
./node_modules/.bin/lessc stylesheets/exercise-content-package/perseus.less $(PERSEUS_BUILD_CSS)
$(PERSEUS_VERSION_FILE): install
mkdir -p build
node node/create-item-version-file.js >> $(PERSEUS_VERSION_FILE)
serve: server
server: install server-offline
server-offline:
(sleep 1; echo; echo http://localhost:$(PORT)/test.html) &
./node_modules/.bin/webpack-dev-server --port $(PORT) --output-public-path live-build/ --devtool inline-source-map src/perseus.js
demo:
git checkout gh-pages
git reset --hard origin/master
make build
git add -f $(PERSEUS_BUILD_JS)
git commit -nm 'demo update'
git checkout master
git push -f origin gh-pages:gh-pages
all: subperseus
subperseus-ios: clean install build put-js-ios
subperseus: clean install shorttest build shortnodetest webapp-put
forcesubperseus: clean install build webapp-put
put-js-ios: build
cp $(PERSEUS_BUILD_JS) "$(IOS)/Resources/webview/javascript/perseus-package/perseus.js"
webapp-put: build
cp $(PERSEUS_BUILD_JS) "$(WEBAPP)/javascript/perseus-package/"
cp $(PERSEUS_NODE_BUILD_JS) "$(WEBAPP)/tools/"
cp stylesheets/perseus-admin-package/* "$(WEBAPP)/stylesheets/perseus-admin-package"
cp $(PERSEUS_BUILD_CSS) "$(WEBAPP)/stylesheets/exercise-content-package/"
cp $(PERSEUS_VERSION_FILE) "$(WEBAPP)/javascript/perseus-admin-package/"
# Pull submodules if they are empty.
# This should make first-time installation easier.
# We don't pull them if they are not empty because you might have
# intentionally added commits to them, and it would be weird for
# running the server to mess around with your git status.
# (we just test kmath here as a fun sample repo. #yolo)
ifeq ("$(wildcard kmath/package.json)", "")
SUBMODULE_UPDATE := git submodule update --init
else
SUBMODULE_UPDATE := @echo "submodules already initialized"
endif
# just to make the upgrade process over switching from injected rcss to
# real rcss smooth
ifeq ("$(wildcard node_modules/rcss/package.json)","")
CLEAN_RCSS := rm -rf node_modules/rcss
else
ifeq ("$(wildcard node_modules/rcss/index.js)","")
CLEAN_RCSS := rm -rf node_modules/rcss
else
CLEAN_RCSS := @echo "rcss already upgraded"
endif
endif
install:
ifneq ("$(SUPPRESSINSTALL)","TRUE")
$(SUBMODULE_UPDATE)
$(CLEAN_RCSS)
npm install
rm -rf node_modules/react-components
ln -s ../react-components/js node_modules/react-components
rm -rf node_modules/kmath
ln -s ../kmath node_modules/kmath
rm -rf node_modules/simple-markdown
ln -s ../simple-markdown node_modules/simple-markdown
rm -rf node_modules/jquery
mkdir -p node_modules/jquery
echo "module.exports = window.$$" > node_modules/jquery/index.js
# very hacks to prevent simple-markdown from pulling in a separate version of react.
# basically, we need its require("react") to resolve to perseus' react, instead of
# one in its node_modules (yuck!) (same for "underscore")
# TODO(aria): cry
rm -rf simple-markdown/node_modules
rm -rf kmath/node_modules
rm -rf react-components/node_modules
endif
clean:
-rm -rf build/*
lint:
~/Khan/devtools/khan-linter/runlint.py
FIND_TESTS_1 := find -E src -type f -regex '.*/__tests__/.*\.jsx?'
FIND_TESTS_2 := find src -type f -regex '.*/__tests__/.*\.jsx?'
ifneq ("$(shell $(FIND_TESTS_1) 2>/dev/null)","")
FIND_TESTS := $(FIND_TESTS_1)
else
ifneq ("$(shell $(FIND_TESTS_2) 2>/dev/null)","")
FIND_TESTS := $(FIND_TESTS_2)
else
FIND_TESTS := @echo "Could not figure out how to run tests; skipping"; @echo ""
endif
endif
test:
$(FIND_TESTS) | xargs ./node_modules/.bin/mocha --reporter spec -r node/environment.js
shorttest:
$(FIND_TESTS) | xargs ./node_modules/.bin/mocha --reporter dot -r node/environment.js
nodetest: $(PERSEUS_NODE_BUILD_JS)
./node_modules/.bin/mocha --reporter dot node/__tests__/require-test.js
shortnodetest: $(PERSEUS_NODE_BUILD_JS)
./node_modules/.bin/mocha --reporter dot node/__tests__/require-test.js
build/ke.js:
(cd ke && ../node_modules/.bin/r.js -o requirejs.config.js out=../build/ke.js)
jest: build/ke.js
./node_modules/.bin/jest