-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
51 lines (39 loc) · 960 Bytes
/
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
ENTRY = lib/index
UMD_NAME = Roff
all: lint umd test
# Generate a compressed UMD bundle from ESM source
umd: lib/index.js
$(ENTRY).js: lib/*/*.mjs lib/*/*/*.mjs
npx rollup \
--format umd \
--preferConst \
--sourcemap [email protected] \
--name $(UMD_NAME) \
--input $(ENTRY).mjs \
--file $@
node -e '\
const fs = require("fs"); \
const map = JSON.parse(fs.readFileSync("[email protected]", "utf8")); \
delete map.sourcesContent; \
fs.writeFileSync("[email protected]", JSON.stringify(map));'
perl -pi~ -E '\
s/new\s+Array\((\d+)\)/$$1<10?"[".","x$$1."]":$$&/ge; \
s/await import\(/require\(/g;' $@ && rm -f "$@~"
npx terser \
--keep-classnames \
--mangle \
--compress \
--source-map "[email protected],url=$(@F).map" \
--output $@ $@
# Wipe generated build targets
clean:
rm -f $(ENTRY).js*
.PHONY: clean
# Check source for style and syntax errors
lint:
npx eslint --ext mjs,js .
.PHONY: lint
# Run unit-tests
test: umd
npx mocha
.PHONY: test