forked from numbas/Numbas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
158 lines (120 loc) · 5.04 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
everything: update_tests docs
VERSION=8.0
NUMBAS_EDITOR_PATH ?= ../editor
JSDOC_TEMPLATE_PATH ?= ../numbas-jsdoc-template
# Location of a clone of https://github.com/numbas/unicode-math-normalization
UNICODE_NORMALIZATION_PATH = ../unicode-math-normalization
RUNTIME_SOURCE_PATH=.
update_tests: jme runtime marking_scripts diagnostic_scripts locales doc_tests
SCRIPTS_DIR=runtime/scripts
MINIMAL_SOURCES=numbas.js localisation.js util.js math.js
THIRD_PARTY_SOURCES=i18next/i18next.js decimal/decimal.js parsel/parsel.js
JME_SOURCES=unicode-mappings.js jme-rules.js jme.js jme-builtins.js jme-display.js jme-variables.js jme-calculus.js
RUNTIME_SOURCES=$(MINIMAL_SOURCES) $(JME_SOURCES) part.js question.js exam.js schedule.js diagnostic.js marking.js json.js timing.js start-exam.js numbas.js scorm-storage.js storage.js xml.js SCORM_API_wrapper.js evaluate-settings.js
PART_SOURCES=$(wildcard $(RUNTIME_SOURCE_PATH)/$(SCRIPTS_DIR)/parts/*.js)
THEME_DIR=themes/default/files/scripts
THEME_SOURCES=answer-widgets.js
ESLINT_THEME_SOURCES = $(THEME_SOURCES) display-base.js display.js exam-display.js mathjax.js part-display.js question-display.js
ESLINT_SOURCES = $(patsubst %, $(SCRIPTS_DIR)/%, $(RUNTIME_SOURCES)) $(patsubst %, $(THEME_DIR)/%, $(ESLINT_THEME_SOURCES)) $(PART_SOURCES)
ALL_SOURCES = $(patsubst %, $(SCRIPTS_DIR)/%, $(RUNTIME_SOURCES) $(THIRD_PARTY_SOURCES)) $(patsubst %, $(THEME_DIR)/%, $(THEME_SOURCES)) $(PART_SOURCES)
define created
@echo -e "\e[32m✓ Created $@\e[0m"
endef
tests/numbas-runtime.js: $(patsubst %, $(RUNTIME_SOURCE_PATH)/%, $(ALL_SOURCES))
@printf "// Compiled using $^\n" > $@
@printf "// From the Numbas compiler directory\n" >> $@
@printf "\"use strict\";\n" >> $@
@for p in $^; do cat $$p >> $@; echo "" >> $@; done
$(created)
runtime: tests/numbas-runtime.js
tests/jme-runtime.js: $(patsubst %, $(RUNTIME_SOURCE_PATH)/$(SCRIPTS_DIR)/%, $(MINIMAL_SOURCES) $(THIRD_PARTY_SOURCES) $(JME_SOURCES))
@echo "// Compiled using $^" > $@
@echo "// From the Numbas compiler directory" >> $@
@for p in $^; do cat $$p >> $@; echo "" >> $@; done
$(created)
jme: tests/jme-runtime.js
MARKING_SCRIPTS=$(wildcard $(RUNTIME_SOURCE_PATH)/marking_scripts/*.jme)
define MARKING_INTRO
Numbas.queueScript('marking_scripts',['marking'],function() {
Numbas.raw_marking_scripts = {
endef
define MARKING_END
};
});
endef
export MARKING_INTRO
export MARKING_END
define encode_marking
echo " \"$(notdir $(basename $(f)))\": " >> $@; cat $(f) | python -c 'import json,sys; sys.stdout.write(json.dumps(sys.stdin.read()))' >> $@;
endef
tests/marking_scripts.js: $(MARKING_SCRIPTS)
@echo "$$MARKING_INTRO" > $@
@$(foreach f,$(wordlist 1,1,$^),$(encode_marking))
@$(foreach f,$(wordlist 2,$(words $^),$^),printf ",\n" >> $@;$(encode_marking))
@echo "$$MARKING_END" >> $@
$(created)
marking_scripts: tests/marking_scripts.js
DIAGNOSTIC_SCRIPTS=$(wildcard $(RUNTIME_SOURCE_PATH)/diagnostic_scripts/*.jme)
define DIAGNOSTIC_INTRO
Numbas.queueScript('diagnostic_scripts',[],function() {
Numbas.raw_diagnostic_scripts = {
endef
define DIAGNOSTIC_END
};
});
endef
export DIAGNOSTIC_INTRO
export DIAGNOSTIC_END
define encode_diagnostic
echo " \"$(notdir $(basename $(f)))\": " >> $@; cat $(f) | python -c 'import json,sys; sys.stdout.write(json.dumps(sys.stdin.read()))' >> $@;
endef
tests/diagnostic_scripts.js: $(DIAGNOSTIC_SCRIPTS)
@echo "$$DIAGNOSTIC_INTRO" > $@
@$(foreach f,$(wordlist 1,1,$^),$(encode_diagnostic))
@$(foreach f,$(wordlist 2,$(words $^),$^),printf ",\n" >> $@;$(encode_diagnostic))
@echo "$$DIAGNOSTIC_END" >> $@
$(created)
diagnostic_scripts: tests/diagnostic_scripts.js
define LOCALES_INTRO
Numbas.queueScript('localisation-resources',['i18next'],function() {
Numbas.locale = {
preferred_locale: "en-GB",
resources: {
endef
define LOCALES_END
}
}
});
endef
export LOCALES_INTRO
export LOCALES_END
define encode_locale
echo " \"$(notdir $(basename $(f)))\": {translation: " | tr '[:upper:]' '[:lower:]' >> $@; cat $(f) >> $@; echo "}" >> $@;
endef
LOCALES=$(wildcard $(RUNTIME_SOURCE_PATH)/locales/*.json)
tests/locales.js: $(LOCALES)
@echo "$$LOCALES_INTRO" > $@
@$(foreach f,$(wordlist 1,1,$^),$(encode_locale))
@$(foreach f,$(wordlist 2,$(words $^),$^),printf ",\n" >> $@;$(encode_locale))
@echo "$$LOCALES_END" >> $@
$(created)
locales: tests/locales.js
docs/index.html: $(ALL_SOURCES) docs.md jsdoc.conf
@echo "Making API documentation..."
jsdoc -c jsdoc.conf -t $(JSDOC_TEMPLATE_PATH)
$(created)
docs: docs/index.html
eslint: $(ESLINT_SOURCES)
@eslint $^
eslint_fix: $(ESLINT_SOURCES)
@eslint --fix $^
tests/jme/doc-tests.mjs: $(NUMBAS_EDITOR_PATH)/docs/jme-reference.rst
@echo "export default" > $@
@cat $^ | python tests/jme/make_tests_from_docs.py >> $@
$(created)
doc_tests: tests/jme/doc-tests.mjs
schema/index.html: schema/make_schema.py schema/exam_schema.$(VERSION).json schema/templates/base.html schema/schema_doc.css schema/schema_doc.js
cd schema; python make_schema.py
schema: schema/index.html
unicode_mappings: $(UNICODE_NORMALIZATION_PATH)/numbas-unicode.js
cp $< runtime/scripts/unicode-mappings.js