-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
81 lines (65 loc) · 2.37 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
NPMBIN=node_modules/.bin
CFCM=$(NPMBIN)/commonform-commonmark
CFHTML=$(NPMBIN)/commonform-html
CFDOCX=$(NPMBIN)/commonform-docx
JSON=$(NPMBIN)/json
BUILD=build
TARGETS=$(addprefix $(BUILD)/,license.html license.docx license.pdf license.md)
all: $(TARGETS)
$(BUILD)/%.json: %.md | $(BUILD) $(CFCM)
$(CFCM) parse $< > $@
$(BUILD)/%.form: $(BUILD)/%.json | $(JSON)
$(JSON) form < $< > $@
$(BUILD)/%.directions: $(BUILD)/%.json | $(BUILD) $(CFCM)
$(JSON) directions < $< > $@
$(BUILD)/%.html: $(BUILD)/%.form $(BUILD)/%.directions $(BUILD)/%.values $(BUILD)/%.title $(BUILD)/%.edition | $(BUILD) $(CFHTML)
$(CFHTML) \
--title "$(shell cat $(BUILD)/$*.title) $(shell cat $(BUILD)/$*.edition)" \
--directions $(BUILD)/$*.directions \
--values $(BUILD)/$*.values \
--ids \
--lists \
--html5 \
--smartify \
< $< | \
sed -E 's!<span class="blank">([^<]+)</span>!\1!g' | \
sed -E 's!(https://[^ ]+)!<a href="\1">\1</a>!g' \
> $@
$(BUILD)/%.docx: $(BUILD)/%.form $(BUILD)/%.directions $(BUILD)/%.values $(BUILD)/%.title $(BUILD)/%.edition styles.json | $(BUILD) $(CFDOCX)
$(CFDOCX) \
--number outline \
--left-align-title \
--indent-margins \
--title "$(shell cat $(BUILD)/$*.title) $(shell cat $(BUILD)/$*.edition)" \
--directions $(BUILD)/$*.directions \
--values $(BUILD)/$*.values \
--styles styles.json \
--smartify \
$< > $@
$(BUILD)/%.md: $(BUILD)/%.form $(BUILD)/%.title $(BUILD)/%.directions $(BUILD)/%.values $(BUILD)/%.edition styles.json | $(BUILD) $(CFCM)
$(CFCM) stringify \
--title "$(shell cat $(BUILD)/$*.title) $(shell cat $(BUILD)/$*.edition)" \
--directions $(BUILD)/$*.directions \
--values $(BUILD)/$*.values \
--ordered \
< $< | \
sed 's/^!!! \(.\+\)$$/***\1***/' | \
sed 's!\\/!/!g' | \
sed -E 's!(https://[^ ]+)!<\1>!g' | \
fmt -u -w64 \
> $@
$(BUILD)/%.title: $(BUILD)/%.json | $(JSON)
$(JSON) frontMatter.title < $< > $@
$(BUILD)/%.edition: $(BUILD)/%.json | $(JSON)
$(JSON) frontMatter.version < $< > $@
$(BUILD)/%.values: $(BUILD)/%.json
node -e 'var value = require("./$(BUILD)/$*.json").frontMatter.version; console.log(JSON.stringify({ version: value === "Development Draft" ? "{version}" : value }))' > $@
$(BUILD)/%.pdf: $(BUILD)/%.docx
soffice --headless --convert-to pdf --outdir $(BUILD) $<
$(BUILD):
mkdir -p $(BUILD)
$(NPMBIN) $(CFCM) $(CFHTML) $(CFDOCX) $(JSON):
npm ci
.PHONY: clean
clean:
rm -rf $(BUILD)