/
Makefile
104 lines (79 loc) · 3.33 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
npmbin=node_modules/.bin
cfcm=$(npmbin)/commonform-commonmark
cfdocx=$(npmbin)/commonform-docx
cfhtml=$(npmbin)/commonform-html
lint=$(npmbin)/commonform-lint
critique=$(npmbin)/commonform-critique
json=$(npmbin)/json
tools=$(cfcm) $(cfdocx) $(lint) $(critique) $(json)
common_form_basenames=confidentiality-ip employee contractor
docx_basenames=offer-letter statement-of-work
all_basenames=$(common_form_basenames) $(docx_basenames)
forms=$(addprefix build/,$(addsuffix .json,$(common_form_basenames)))
VERSION ?= Development Draft
ifeq ($(VERSION),Development Draft)
VERSION_NUMBER=DRAFT
VERSION_STRING=Development Draft
else
VERSION_NUMBER=$(VERSION)
VERSION_STRING=Version $(VERSION)
# Note the non-breaking space in the line above.
endif
all: docx pdf html rtf
docx: $(foreach basename,$(all_basenames:=.docx),$(addprefix build/,$(basename)))
rtf: $(foreach basename,$(all_basenames:=.rtf),$(addprefix build/,$(basename)))
pdf: $(foreach basename,$(all_basenames:=.pdf),$(addprefix build/,$(basename)))
html: $(foreach basename,$(common_form_basenames:=.html),$(addprefix build/,$(basename)))
build/%.docx: %.html reference.docx | build
cat $< \
| sed "s/VERSION_NUMBER/$(VERSION_NUMBER)/g" \
| sed "s/VERSION_STRING/$(VERSION_STRING)/g" \
| pandoc -f html -o $@ --reference-doc reference.docx
build/%.rtf: build/%.docx | build
soffice --headless --convert-to rtf --outdir build $<
build/%.docx: build/%.json build/%.title build/%.directions build/%.blanks build/%.signatures styles.json | $(cfdocx) build
$(cfdocx) --title "$(shell cat build/$*.title)" --form-version "$(VERSION_STRING)" --number outline --left-align-title --smart --indent-margins --styles styles.json --values build/$*.blanks --directions build/$*.directions --signatures build/$*.signatures $< > $@
build/%.html: build/%.json build/%.title build/%.directions build/%.blanks build/%.signatures styles.json | $(cfdocx) build
$(cfhtml) --html5 --smart --lists --ids --title "$(shell cat build/$*.title)" --form-version "$(VERSION_STRING)" --values build/$*.blanks --directions build/$*.directions --signatures build/$*.signatures < $< > $@
build/%.title: build/%.parsed | $(json) build
$(json) frontMatter.title < $< > $@
build/%.json: build/%.parsed | $(json) build
$(json) form < $< > $@
build/%.blanks: build/%.parsed | $(json) build
$(json) frontMatter.blanks < $< > $@
build/%.signatures: build/%.parsed | $(json) build
$(json) frontMatter.signatures < $< > $@
build/%.directions: build/%.parsed | $(json) build
$(json) directions < $< > $@
build/%.parsed: %.md | $(cfcm) build
cat $< \
| sed "s/VERSION_NUMBER/$(VERSION_NUMBER)/g" \
| sed "s/VERSION_STRING/$(VERSION_STRING)/g" \
| $(cfcm) parse > $@
build/%.pdf: build/%.docx
soffice --headless --convert-to pdf --outdir build $<
build:
mkdir -p $@
$(tools):
npm ci
.PHONY: lint critique clean docker
lint: $(forms) | $(lint) $(json)
@for form in $(forms); do \
echo ; \
echo $$form; \
cat $$form | $(lint) | $(json) -a message | sort -u; \
done; \
critique: $(forms) | $(critique) $(json)
@for form in $(forms); do \
echo ; \
echo $$form ; \
cat $$form | $(critique) | $(json) -a message | sort -u; \
done
clean:
rm -rf build
dockertag=square-one-forms
docker:
docker build -t $(dockertag) .
docker run --name $(dockertag) $(dockertag)
docker cp $(dockertag):/workdir/build .
docker rm $(dockertag)