-
Notifications
You must be signed in to change notification settings - Fork 63
/
build.sh
executable file
·135 lines (114 loc) · 3.53 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
#!/bin/bash
### Define variables that we need for this script
### These are the chapters are are currently done. Add chapters here.
allDocuments=('blank' 'index' '1' '2' '3' '4' '5' '6' '7' '8' '9' '10' '11'
'12' '13' '14' 'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I')
allChapters=('1' '2' '3' '4' '5' '6' '7' '8' '9' '10' '11'
'12' '13' '14' 'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I')
misc=('blank' 'index')
chaptersWithFolders=('2' '3' '4' '5' '6' '7' '9' '12' '14' 'B' 'C' 'D' 'F' 'G' 'H')
chaptersWithOutFolders=('1' '8' '10' '11' '13' 'A' 'E' 'I')
foundDirs=()
### Turn on globbing (BASH 4 required)
shopt -s globstar
hello() {
echo "Building the Cocos2d-x Programmers Guide..."
echo ""
echo "You can pass in --help for help on how to use this script."
echo ""
}
help() {
## State what we need for this script to run
echo "this script reqires: "
echo ""
echo "mkdocs: http://www.mkdocs.org/"
echo "Grip - https://github.com/joeyespo/grip"
echo "PrinceXML - https://princexml.com"
echo "Bash 4.0: brew install bash"
echo ""
}
cleanUp() {
echo "cleaning up cruft..."
rm -rf print/
}
exitScript() {
echo "exiting...."
exit 0
}
deployToGitHub() {
echo "deploying to GitHub Pages: ..."
rsync -a site/ ../ChukongUSA.github.io/programmers-guide
cd ../ChukongUSA.github.io/programmers-guide
git add .
git commit -m 'published automatically from script'
git push
cd ../../programmers-guide
}
buildHTML() {
echo "building the html version with mkdocs..."
echo "output is in site/..."
echo "copying resources to respective directories..."
rm -rf docs/
mkdir -p docs
mkdir -p print
for i in ${chaptersWithFolders[@]}; do
rsync -a chapters/${i}-web docs/
rsync -a chapters/${i}-print print/
mv docs/${i}-web docs/${i}-img
mv print/${i}-print print/${i}-img
cp chapters/${i}.md docs/${i}.md
cp chapters/${i}.md print/${i}.md
done
for i in ${chaptersWithOutFolders[@]}; do
cp chapters/${i}.md docs/${i}.md
cp chapters/${i}.md print/${i}.md
done
for i in ${misc[@]}; do
cp chapters/${i}.md docs/${i}.md
cp chapters/${i}.md print/${i}.md
done
## Now we can use MKDocs to build the static content
echo "MKDocs Build..."
rm -rf site/
mkdocs build
## Now, lets copy the img folder to each chapter, we need to do this for theme
## path issues in the fact each directory is treated separately.
## We will get some errors here for chapters that dont yet exist
for i in ${allChapters[@]}; do
rsync -a theme/img site/${i}/
done
}
buildPrint() {
## create HTML docs from the markdown files in the above array
echo "building print version..."
for i in "${allDocuments[@]}"; do
grip --user <user> --pass <pass> --gfm print/${i}.md --export print/${i}.html
## insert the proper style that princeXML needs
strToInsert='<style> @page { prince-shrink-to-fit: none } .repository-content {width: 900px ! important;} @page { margin: 40pt 10pt 40pt 10pt;}</style>'
sed -i.bak "s#</head>#$strToInsert </head>#" print/${i}.html
done
echo "building the PDF..."
cd print/
prince index.html "${allChapters[@]/%/.html}" -o ../ProgrammersGuide.pdf
cd ..
cp ProgrammersGuide.pdf site/.
}
main() {
## display opening message to user
hello
## See what parameters the user has supplied.
if (( $# == 1 )); then
if [[ "--help" =~ $1 ]]; then ## user asked for help
help
exit 0
fi
fi
## we don't need parameters to run the script so build the documentation
buildHTML
buildPrint
deployToGitHub
cleanUp
exitScript
}
## run our script.
main $1