forked from mathquill/mathquill
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Makefile
192 lines (161 loc) · 6.27 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#
# -*- Prerequisites -*-
#
# the fact that 'I am Node.js' is unquoted here looks wrong to me but it
# CAN'T be quoted, I tried. Apparently in GNU Makefiles, in the paren+comma
# syntax for conditionals, quotes are literal; and because the $(shell...)
# call has parentheses and single and double quotes, the quoted syntaxes
# don't work (I tried), we HAVE to use the paren+comma syntax
ifneq ($(shell node -e 'console.log("I am Node.js")'), I am Node.js)
ifeq ($(shell nodejs -e 'console.log("I am Node.js")' 2>/dev/null), I am Node.js)
$(error You have /usr/bin/nodejs but no /usr/bin/node, please 'sudo apt-get install nodejs-legacy' (see http://stackoverflow.com/a/21171188/362030 ))
endif
$(error Please install Node.js: https://nodejs.org/ )
endif
#
# -*- Configuration -*-
#
# inputs
SRC_DIR = ./src
INTRO = $(SRC_DIR)/intro.js
OUTRO = $(SRC_DIR)/outro.js
BASE_SOURCES = \
$(SRC_DIR)/utils.ts \
$(SRC_DIR)/dom.ts \
$(SRC_DIR)/unicode.ts \
$(SRC_DIR)/browser.ts \
$(SRC_DIR)/animate.ts \
$(SRC_DIR)/services/aria.ts \
$(SRC_DIR)/domFragment.ts \
$(SRC_DIR)/tree.ts \
$(SRC_DIR)/cursor.ts \
$(SRC_DIR)/controller.ts \
$(SRC_DIR)/publicapi.ts \
$(SRC_DIR)/services/parser.util.ts \
$(SRC_DIR)/services/saneKeyboardEvents.util.ts \
$(SRC_DIR)/services/exportText.ts \
$(SRC_DIR)/services/focusBlur.ts \
$(SRC_DIR)/services/keystroke.ts \
$(SRC_DIR)/services/latex.ts \
$(SRC_DIR)/services/mouse.ts \
$(SRC_DIR)/services/scrollHoriz.ts \
$(SRC_DIR)/services/textarea.ts
SOURCES_FULL = \
$(BASE_SOURCES) \
$(SRC_DIR)/commands/math.ts \
$(SRC_DIR)/commands/text.ts \
$(SRC_DIR)/commands/math/advancedSymbols.ts \
$(SRC_DIR)/commands/math/basicSymbols.ts \
$(SRC_DIR)/commands/math/commands.ts \
$(SRC_DIR)/commands/math/LatexCommandInput.ts
SOURCES_BASIC = \
$(BASE_SOURCES) \
$(SRC_DIR)/commands/math.ts \
$(SRC_DIR)/commands/math/basicSymbols.ts \
$(SRC_DIR)/commands/math/commands.ts
CSS_DIR = $(SRC_DIR)/css
CSS_MAIN = $(CSS_DIR)/main.less
CSS_SOURCES = $(shell find $(CSS_DIR) -name '*.less')
FONT_SOURCE = $(SRC_DIR)/fonts
FONT_TARGET = $(BUILD_DIR)/fonts
TEST_SUPPORT = ./test/support/assert.ts ./test/support/trigger-event.ts ./test/support/jquery-stub.ts
UNIT_TESTS = ./test/unit/*.test.js ./test/unit/*.test.ts
# outputs
VERSION ?= $(shell node -e "console.log(require('./package.json').version)")
BUILD_DIR = ./build
BUILD_JS = $(BUILD_DIR)/mathquill.js
BASIC_JS = $(BUILD_DIR)/mathquill-basic.js
BUILD_CSS = $(BUILD_DIR)/mathquill.css
BASIC_CSS = $(BUILD_DIR)/mathquill-basic.css
BUILD_TEST = $(BUILD_DIR)/mathquill.test.js
UGLY_JS = $(BUILD_DIR)/mathquill.min.js
UGLY_BASIC_JS = $(BUILD_DIR)/mathquill-basic.min.js
# programs and flags
UGLIFY ?= ./node_modules/.bin/uglifyjs
UGLIFY_OPTS ?= --mangle --compress hoist_vars=true --comments /maintainers@mathquill.com/
LESSC ?= ./node_modules/.bin/lessc
LESS_OPTS ?=
ifdef OMIT_FONT_FACE
LESS_OPTS += --modify-var="omit-font-face=true"
endif
# Empty target files whose Last Modified timestamps are used to record when
# something like `npm install` last happened (which, for example, would then be
# compared with its dependency, package.json, so if package.json has been
# modified since the last `npm install`, Make will `npm install` again).
# http://www.gnu.org/software/make/manual/html_node/Empty-Targets.html#Empty-Targets
NODE_MODULES_INSTALLED = ./node_modules/.installed--used_by_Makefile
BUILD_DIR_EXISTS = $(BUILD_DIR)/.exists--used_by_Makefile
# environment constants
#
# -*- Build tasks -*-
#
.PHONY: all basic dev js uglify css font clean setup-gitconfig prettify-all
all: font css uglify
basic: $(UGLY_BASIC_JS) $(BASIC_CSS)
unminified_basic: $(BASIC_JS) $(BASIC_CSS)
# dev is like all, but without minification
dev: font css js
js: $(BUILD_JS)
uglify: $(UGLY_JS)
css: $(BUILD_CSS)
font: $(FONT_TARGET)
clean:
rm -rf $(BUILD_DIR)
# This adds an entry to your local .git/config file that looks like this:
# [include]
# path = ../.gitconfig
# that tells git to include the additional configuration specified inside the .gitconfig file that's checked in here.
setup-gitconfig:
@git config --local include.path ../.gitconfig
prettify-all:
npx prettier --write '**/*.{ts,js,css,html}'
$(BUILD_JS): $(INTRO) $(SOURCES_FULL) $(OUTRO) $(BUILD_DIR_EXISTS)
cat $^ | ./script/escape-non-ascii | ./script/tsc-emit-only > $@
perl -pi -e s/mq-/$(MQ_CLASS_PREFIX)mq-/g $@
perl -pi -e s/{VERSION}/v$(VERSION)/ $@
$(UGLY_JS): $(BUILD_JS) $(NODE_MODULES_INSTALLED)
$(UGLIFY) $(UGLIFY_OPTS) < $< > $@
$(BASIC_JS): $(INTRO) $(SOURCES_BASIC) $(OUTRO) $(BUILD_DIR_EXISTS)
cat $^ | ./script/escape-non-ascii | ./script/tsc-emit-only > $@
perl -pi -e s/mq-/$(MQ_CLASS_PREFIX)mq-/g $@
perl -pi -e s/{VERSION}/v$(VERSION)/ $@
$(UGLY_BASIC_JS): $(BASIC_JS) $(NODE_MODULES_INSTALLED)
$(UGLIFY) $(UGLIFY_OPTS) < $< > $@
$(BUILD_CSS): $(CSS_SOURCES) $(NODE_MODULES_INSTALLED) $(BUILD_DIR_EXISTS)
$(LESSC) $(LESS_OPTS) $(CSS_MAIN) > $@
perl -pi -e s/mq-/$(MQ_CLASS_PREFIX)mq-/g $@
perl -pi -e s/{VERSION}/v$(VERSION)/ $@
$(BASIC_CSS): $(CSS_SOURCES) $(NODE_MODULES_INSTALLED) $(BUILD_DIR_EXISTS)
$(LESSC) --modify-var="basic=true" $(LESS_OPTS) $(CSS_MAIN) > $@
perl -pi -e s/mq-/$(MQ_CLASS_PREFIX)mq-/g $@
perl -pi -e s/{VERSION}/v$(VERSION)/ $@
$(NODE_MODULES_INSTALLED): package.json
test -e $(NODE_MODULES_INSTALLED) || rm -rf ./node_modules/ # robust against previous botched npm install
NODE_ENV=development npm ci
touch $(NODE_MODULES_INSTALLED)
$(BUILD_DIR_EXISTS):
mkdir -p $(BUILD_DIR)
touch $(BUILD_DIR_EXISTS)
$(FONT_TARGET): $(FONT_SOURCE) $(BUILD_DIR_EXISTS)
rm -rf $@
cp -r $< $@
#
# -*- Test tasks -*-
#
.PHONY:
lint:
npx tsc --noEmit
# Make sure that the public, standalone type definitions do not depend on any internal sources.
npx tsc --noEmit -p test/tsconfig.public-types-test.json
.PHONY: test server benchmark
server:
node script/test_server.js
test: dev $(BUILD_TEST) $(BASIC_JS) $(BASIC_CSS)
@echo
@echo "** now open test/{unit,visual}.html in your browser to run the {unit,visual} tests. **"
benchmark: dev $(BUILD_TEST) $(BASIC_JS) $(BASIC_CSS)
@echo
@echo "** now open benchmark/{render,select,update}.html in your browser. **"
$(BUILD_TEST): $(INTRO) $(SOURCES_FULL) $(TEST_SUPPORT) $(UNIT_TESTS) $(OUTRO) $(BUILD_DIR_EXISTS)
cat $^ | ./script/tsc-emit-only > $@
perl -pi -e s/{VERSION}/v$(VERSION)/ $@