-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·83 lines (68 loc) · 1.35 KB
/
build.sh
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
#!/bin/bash
set -e
export SCRIPT="$0"
export FORMAT="$1"
FORMAT="${FORMAT:-all}"
export ADOC="$2"
ADOC="${ADOC:-*.adoc}"
export GEM_HOME=~/.gem
function usage() {
echo "USAGE: $SCRIPT <all|html|pdf> <adoc file>"
echo 'Supported formats: all, html, pdf'
}
function install_dependencies() {
mkdir -p ~/.gem
if [[ "$(gem list -i '^asciidoctor$')" == "false" ]]; then
bundle install
fi
}
function asciidoctor() {
bundle exec asciidoctor "$@"
}
function asciidoctor-pdf() {
bundle exec asciidoctor-pdf "$@"
}
function expect_adoc() {
if [ -z "$ADOC" ]; then
echo 'ERROR: missing adoc file path argument!' > /dev/stderr
usage
return 1
fi
}
function check_spelling() {
npx cspell *.adoc
}
function generate_html() {
expect_adoc
install_dependencies
asciidoctor "$ADOC"
}
function generate_pdf() {
expect_adoc
install_dependencies
asciidoctor-pdf --trace "$ADOC"
}
case "$FORMAT" in
html|HTML)
check_spelling
generate_html
;;
pdf|PDF)
check_spelling
generate_pdf
;;
all|ALL)
check_spelling
generate_html
generate_pdf
;;
-h|--help)
usage
;;
*)
echo "ERROR: unknown format $FORMAT" > /dev/stderr
usage
exit 1
;;
esac
echo 'done!'