forked from hazelcast/hazelcast-reference-manual
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·217 lines (191 loc) · 6.67 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/bash
function buildDocumentation {
init $1
cleanIfExists
copyImages
createMultiHTML
createMergedMarkdownFile
createSingleHTML
createMancenterDocumentation
if [ "$2" != "--skipPDF" ]; then
createPDF
fi
delete
echo "Done"
}
function init {
VERSION=$1
OUTPUT_DIR="target"
MULTI_HTML_OUTPUT_DIR="html"
SINGLE_HTML_OUTPUT_DIR="html-single"
MANCENTER_OUTPUT_DIR="mancenter"
PDF_OUTPUT_DIR="pdf"
PDF_FILE_NAME="hazelcast-documentation-${VERSION}.pdf"
MANIFEST_FILE_NAME="manifest.json"
MERGED_FILE_NAME="index.md"
COPYRIGHT_FILE_NAME="copyright.txt"
DATE=`LANG=en_EN date +%b\ %d\,\ %Y`
YEAR=`LANG=en_EN date +%Y`
INDEX=`awk '{gsub(/^[ \t]+|^([#]+.*)|[ \t]+([#]+.*)\$/,""); print;}' documentation.index`
MANCENTER_INDEX=`awk '{gsub(/^[ \t]+|([#]+.*)|[ \t]+([#]+.*)\$/,""); print;}' mancenter.index`
}
function cleanIfExists {
if [ -e "./$OUTPUT_DIR" ]; then
echo "Cleaning $OUTPUT_DIR"
$(rm -rf "./$OUTPUT_DIR")
fi
echo "Creating $OUTPUT_DIR"
mkdir ${OUTPUT_DIR}
echo "Creating $OUTPUT_DIR/$MULTI_HTML_OUTPUT_DIR"
mkdir ${OUTPUT_DIR}/${MULTI_HTML_OUTPUT_DIR}
echo "Creating $OUTPUT_DIR/$SINGLE_HTML_OUTPUT_DIR"
mkdir ${OUTPUT_DIR}/${SINGLE_HTML_OUTPUT_DIR}
echo "Creating $OUTPUT_DIR/$MANCENTER_OUTPUT_DIR"
mkdir ${OUTPUT_DIR}/${MANCENTER_OUTPUT_DIR}
echo "Creating $OUTPUT_DIR/$PDF_OUTPUT_DIR"
mkdir ${OUTPUT_DIR}/${PDF_OUTPUT_DIR}
}
function copyImages {
# BeautifulDocs is not working reliable when copying images, so we copy the files manually (bug is reported)
if [ ! -d "./src/images" ]; then
mkdir ./src/images
fi
cp -aR ./images/. ./src/images/.
mkdir ./${OUTPUT_DIR}/${MULTI_HTML_OUTPUT_DIR}"/images/"
mkdir ./${OUTPUT_DIR}/${SINGLE_HTML_OUTPUT_DIR}"/images/"
mkdir ./${OUTPUT_DIR}/${MANCENTER_OUTPUT_DIR}"/images/"
cp -aR ./images/ ./${OUTPUT_DIR}/${MULTI_HTML_OUTPUT_DIR}"/images/"
cp -aR ./images/ ./${OUTPUT_DIR}/${SINGLE_HTML_OUTPUT_DIR}"/images/"
cp -aR ./images/ ./${OUTPUT_DIR}/${MANCENTER_OUTPUT_DIR}"/images/"
}
function writeManifestFile {
if [[ -e "./$MANIFEST_FILE_NAME" ]]; then
$(rm -rf "./$MANIFEST_FILE_NAME")
fi
writeManifest=$( echo $1 >> ${MANIFEST_FILE_NAME})
if [[ $? -eq 0 ]]; then
echo "Manifest file successfully written"
else
echo "Error writing manifest file"
echo ${writeManifest}
delete
exit -1
fi
}
function createMultiHTML {
MANIFEST_FILE_BODY="{\"title\": \"Documentation\",
\"rootDir\": \".\",
\"date\": \"${DATE}\",
\"version\": \"${VERSION}\",
\"maxTocLevel\":3,
\"files\":"
MANIFEST_FILE_BODY+="["
echo "Building manifest file for multipage html"
for file in ${INDEX}; do
MANIFEST_FILE_BODY+="\"$file\","
done
MANIFEST_FILE_BODY=${MANIFEST_FILE_BODY:0: ${#MANIFEST_FILE_BODY}-1}
MANIFEST_FILE_BODY+="]}"
writeManifestFile "${MANIFEST_FILE_BODY}"
echo "Creating multi_html documentation"
createHtml=$(bfdocs --theme=themes/multi_html "./"${MANIFEST_FILE_NAME} "./"${OUTPUT_DIR}/${MULTI_HTML_OUTPUT_DIR})
if [[ $? -ge 0 ]]; then
echo "Multi HTML created successfully"
else
echo "Error creating Multi HTML documentation"
delete
exit -1
fi
}
function createMergedMarkdownFile {
if [[ -e "./$MERGED_FILE_NAME" ]]; then
$(rm -rf "./$MERGED_FILE_NAME")
fi
echo "Creating concatenated markdown file for pdf/single html"
for file in ${INDEX}; do
cat ${file} >> ${MERGED_FILE_NAME}
printf "\n\n\n" >> ${MERGED_FILE_NAME}
done
}
function createSingleHTML {
MANIFEST_FILE_BODY="{\"title\": \"Documentation\",
\"rootDir\": \".\",
\"date\": \"${DATE}\",
\"version\": \"${VERSION}\",
\"maxTocLevel\":3,
\"files\":[\"./$MERGED_FILE_NAME\"]}"
writeManifestFile "${MANIFEST_FILE_BODY}"
echo "Creating single_html documentation"
createHtml=$(bfdocs --theme=themes/single_html ${MANIFEST_FILE_NAME} "./"${OUTPUT_DIR}/${SINGLE_HTML_OUTPUT_DIR} )
if [[ $? -eq 0 ]]; then
echo "Single HTML created successfully"
else
echo "Error creating Single HTML documentation"
delete
exit -1
fi
}
function createMancenterDocumentation {
MANIFEST_FILE_BODY="{\"title\": \"Documentation\",
\"rootDir\": \".\",
\"date\": \"${DATE}\",
\"version\": \"${VERSION}\",
\"maxTocLevel\":3,
\"files\":"
MANIFEST_FILE_BODY+="["
echo "Building manifest file for mancenter"
for file in ${MANCENTER_INDEX}; do
MANIFEST_FILE_BODY+="\"$file\","
done
MANIFEST_FILE_BODY=${MANIFEST_FILE_BODY:0: ${#MANIFEST_FILE_BODY}-1}
MANIFEST_FILE_BODY+="]}"
writeManifestFile "${MANIFEST_FILE_BODY}"
echo "Creating Management Center documentation"
createHtml=$(bfdocs --theme=themes/no_header ${MANIFEST_FILE_NAME} "./"${OUTPUT_DIR}/${MANCENTER_OUTPUT_DIR} )
if [[ $? -eq 0 ]]; then
echo "Management Center documentation created successfully"
else
echo "Error creating Management Center documentation"
delete
exit -1
fi
}
function createPDF {
if [ -e "./$COPYRIGHT_FILE_NAME" ]; then
$(rm -rf "./$COPYRIGHT_FILE_NAME")
fi
echo "Preparing Copyright Text"
printf "In-Memory Data Grid - Hazelcast | Documentation: version ${VERSION} \n\n" >> ${COPYRIGHT_FILE_NAME}
printf "Publication date ${DATE}\n\n" >> ${COPYRIGHT_FILE_NAME}
printf "Copyright © ${YEAR} Hazelcast, Inc.\n\n\n" >> ${COPYRIGHT_FILE_NAME}
printf "Permission to use, copy, modify and distribute this document for any purpose and without fee is hereby granted in perpetuity, provided that the above copyright notice
and this paragraph appear in all copies." >> ${COPYRIGHT_FILE_NAME}
echo "Copyright text created successfully"
if [[ -e "./title.txt" ]]; then
$(rm -rf "./title.txt")
fi
echo "Creating title page"
echo "%Hazelcast Documentation" >> title.txt
echo "%version "${VERSION} >> title.txt
echo "%"${DATE} >> title.txt
echo "Creating PDF Documentation"
createPDF=$( pandoc title.txt ${MERGED_FILE_NAME} -o ${PDF_FILE_NAME} --toc --toc-depth=3 --chapters --number-sections --tab-stop=2 -V papersize:"a4paper" -H themes/margin.sty --include-before-body=${COPYRIGHT_FILE_NAME} )
if [[ $? -eq 0 ]]; then
echo "PDF created successfully"
else
echo "Error creating PDF documentation"
echo ${createPDF}
delete
exit -1
fi
mv ${PDF_FILE_NAME} ./${OUTPUT_DIR}/${PDF_OUTPUT_DIR}/${PDF_FILE_NAME}
}
function delete {
echo "Deleting created files"
$(rm -rf "./$COPYRIGHT_FILE_NAME")
$(rm -rf "./$MERGED_FILE_NAME")
$(rm -rf "./$MANIFEST_FILE_NAME")
$(rm -rf "./title.txt")
$(rm -rf "./src/images")
}
buildDocumentation $@