-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
155 lines (114 loc) · 5.08 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
# Licensed under the MIT License
# https://github.com/craigahobbs/bare-script/blob/main/LICENSE
# Download javascript-build
define WGET
ifeq '$$(wildcard $(notdir $(1)))' ''
$$(info Downloading $(notdir $(1)))
_WGET := $$(shell $(call WGET_CMD, $(1)))
endif
endef
WGET_CMD = if which wget; then wget -q -c $(1); else curl -f -Os $(1); fi
$(eval $(call WGET, https://craigahobbs.github.io/javascript-build/Makefile.base))
$(eval $(call WGET, https://craigahobbs.github.io/javascript-build/jsdoc.json))
$(eval $(call WGET, https://craigahobbs.github.io/javascript-build/eslint.config.js))
# Include javascript-build
include Makefile.base
ESLINT_ARGS := $(ESLINT_ARGS) bin/ perf/
help:
@echo " [perf|test-doc]"
clean:
rm -rf Makefile.base jsdoc.json eslint.config.js
doc:
# Copy statics
cp -R static/* build/doc/
# Generate the library documentation
$(NODE_DOCKER) npx baredoc lib/library.js -o build/doc/library/library.json
# Generate the expression library documentation
$(NODE_DOCKER) node --input-type=module -e "$$DOC_EXPR_JS" build/doc/library/library.json build/doc/library/expression.json
# Generate the library model documentation
$(NODE_DOCKER) node --input-type=module -e "$$DOC_LIBRARY_MODEL_JS" build/doc/library/model.json
# Generate the runtime model documentation
$(NODE_DOCKER) node --input-type=module -e "$$DOC_RUNTIME_MODEL_JS" build/doc/model/model.json
# JavaScript to generate the expression library documentation
define DOC_EXPR_JS
import {readFileSync, writeFileSync} from 'node:fs';
import {argv} from 'node:process';
import {expressionFunctionMap} from './lib/library.js';
import {valueJSON} from './lib/value.js';
// Command-line arguments
const [, libraryPath, expressionPath] = argv;
// Read the script library documentation model
const library = JSON.parse(readFileSync(libraryPath, {'encoding': 'utf-8'}));
// Create the expression documentation model
const libraryMap = Object.fromEntries(library.functions.map((func) => [func.name, func]));
const libraryExpr = {'functions': []};
for (const [exprFnName, scriptFnName] of Object.entries(expressionFunctionMap)) {
libraryExpr.functions.push({...libraryMap[scriptFnName], 'name': exprFnName});
}
// Write the expression documentation model
writeFileSync(expressionPath, valueJSON(libraryExpr));
endef
export DOC_EXPR_JS
# JavaScript to generate the library model documentation
define DOC_LIBRARY_MODEL_JS
import {regexMatchTypes, systemFetchTypes} from './lib/library.js';
import {aggregationTypes} from './lib/data.js';
import {argv} from 'node:process';
import {valueJSON} from './lib/value.js';
import {writeFileSync} from 'node:fs';
// Command-line arguments
const [, typeModelPath] = argv;
// Create the library type model
const types = {...aggregationTypes, ...regexMatchTypes, ...systemFetchTypes};
// Write the library type model
writeFileSync(typeModelPath, valueJSON(types));
endef
export DOC_LIBRARY_MODEL_JS
# JavaScript to generate the runtime model documentation
define DOC_RUNTIME_MODEL_JS
import {argv} from 'node:process';
import {bareScriptTypes} from './lib/model.js';
import {valueJSON} from './lib/value.js';
import {writeFileSync} from 'node:fs';
// Command-line arguments
const [, typeModelPath] = argv;
// Write the runtime type model
writeFileSync(typeModelPath, valueJSON(bareScriptTypes));
endef
export DOC_RUNTIME_MODEL_JS
.PHONY: test-doc
commit: test-doc
test-doc: build/npm.build
$(NODE_DOCKER) npx bare -s static/library/*.mds static/library/test/*.mds
$(NODE_DOCKER) npx bare -c "include <markdownUp.bare>" static/library/test/runTests.mds$(if $(DEBUG), -d)$(if $(TEST), -v vTest "'$(TEST)'")
# Run performance tests
.PHONY: perf
perf: build/npm.build
mkdir -p $(dir $(PERF_JSON))
echo "[" > $(PERF_JSON)
for X in $$(seq 1 $(PERF_RUNS)); do echo '{"language": "BareScript", "timeMs": '$$($(NODE_DOCKER) npx bare perf/test.bare)'},' >> $(PERF_JSON); done
for X in $$(seq 1 $(PERF_RUNS)); do echo '{"language": "JavaScript", "timeMs": '$$($(NODE_DOCKER) node perf/test.js)'},' >> $(PERF_JSON); done
for X in $$(seq 1 $(PERF_RUNS)); do echo '{"language": "Python", "timeMs": '$$($(PYTHON_DOCKER) python3 perf/test.py)'},' >> $(PERF_JSON); done
echo '{"language": null, "timeMs": null}' >> $(PERF_JSON)
echo "]" >> $(PERF_JSON)
$(NODE_DOCKER) node --input-type=module -e "$$PERF_JS"
# Performance test constants
PERF_JSON := build/perf.json
PERF_RUNS := 3
# JavsScript to report on performance test data
define PERF_JS
import {readFileSync} from 'node:fs';
// Read the performance test data
const bestTimings = {};
for (const {language, timeMs} of JSON.parse(readFileSync('$(PERF_JSON)'))) {
if (language !== null && (!(language in bestTimings) || timeMs < bestTimings[language])) {
bestTimings[language] = timeMs;
}
}
// Report the timing multiples
for (const [language, timeMs] of Object.entries(bestTimings).sort(([, timeMs1], [, timeMs2]) => timeMs2 - timeMs1)) {
const report = `$${language} - $${timeMs.toFixed(3)} milliseconds`;
console.log(language === 'BareScript' ? report : `$${report} ($${(bestTimings.BareScript / timeMs).toFixed(0)}x)`);
}
endef
export PERF_JS