Newer
Older
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
#!/bin/bash
output=/dev/stdout
name=FC_pregmod
# displays help text
function displayHelp() {
cat <<HelpText
Usage: compile.sh [OPTION]...
Options:
-d, --dry Do not compile
-g, --git Add hash of HEAD to filename
-h, --help Show this help text
-s, --sanity Run sanityCheck
-q, --quiet Suppress terminal output
-t, --themes Generate theme files
-m, --minify Minify output files
--ci CI mode
-f, --f Final file name
HelpText
}
#display an error message
function echoError() {
echo -e "\033[0;31m$*\033[0m"
}
#display message
function echoMessage() {
echo "$1" >"${output}"
}
#compile the HTML file
function compile() {
mkdir -p bin/resources
export TWEEGO_PATH=devTools/tweeGo/storyFormats
TWEEGO_EXE="tweego"
if hash $TWEEGO_EXE 2>/dev/null; then
echoMessage "system tweego binary"
else
case "$(uname -m)" in
x86_64 | amd64)
echoMessage "x64 arch"
if [ "$(uname -s)" = "Darwin" ]; then
TWEEGO_EXE="./devTools/tweeGo/tweego_osx64"
elif [ "$OSTYPE" = "msys" ]; then
TWEEGO_EXE="./devTools/tweeGo/tweego_win64"
else
TWEEGO_EXE="./devTools/tweeGo/tweego_nix64"
fi
;;
x86 | i[3-6]86)
echoMessage "x86 arch"
if [ "$(uname -s)" = "Darwin" ]; then
TWEEGO_EXE="./devTools/tweeGo/tweego_osx86"
elif [ "$OSTYPE" = "msys" ]; then
TWEEGO_EXE="./devTools/tweeGo/tweego_win86"
else
TWEEGO_EXE="./devTools/tweeGo/tweego_nix86"
fi
;;
*)
echoError "No system tweego binary found, and no precompiled binary for your platform available."
echoError "Please compile tweego and put the executable in PATH."
exit 2
;;
esac
fi
if [ "$(uname -m)" = "x86_64" ] || [ "$(uname -m)" = "amd64" ]; then
if [ "$(uname -s)" = "Darwin" ]; then
MINIFY_EXE="./devTools/minify/minify_darwin_amd64"
elif [ "$OSTYPE" = "msys" ]; then
MINIFY_EXE="./devTools/minify/minify_win_amd64.exe"
else
MINIFY_EXE="./devTools/minify/minify_linux_amd64"
fi
fi
file="bin/${name}.html"
# Find and insert current commit
if [[ "$ci" ]]; then
COMMIT=$CI_COMMIT_SHORT_SHA
elif [[ -d .git ]]; then
COMMIT=$(git rev-parse --short HEAD)
if [[ "$usehash" ]]; then
file="bin/${name}${COMMIT}.html"
fi
fi
if [[ "$minify" ]]; then
final_file=$file
file="bin/tmp.html"
fi
if [[ "$COMMIT" ]]; then
printf "App.Version.commitHash = '%s';\n" "${COMMIT}" > src/002-config/fc-version.js.commitHash.js
fi
devTools/concatFiles.sh js/ '*.js' bin/fc.js
devTools/concatFiles.sh css/ '*.css' bin/fc.css
$TWEEGO_EXE -o "$file" --module=bin/fc.js --module=bin/fc.css --head resources/raster/favicon/arcologyVector.html src/ || build_failed="true"
rm -f bin/fc.js
rm -f bin/fc.css
if [ "$build_failed" = "true" ]; then
echoError "Build failed."
exit 1
fi
if [[ "$minify" ]]; then
if [[ "$MINIFY_EXE" ]]; then
# SC license is inside an HTML comment, so keep them.
# eval depends on local variables, so don't modify them (Config, Engine, ...)
$MINIFY_EXE --html-keep-comments --js-keep-var-names "$file" > "$final_file"
rm -f "$file"
else
echoError "Minification only available on amd64 systems."
mv "$file" "$final_file"
fi
file=$final_file
fi
if [[ "$ci" || -d .git ]]; then
rm src/002-config/fc-version.js.commitHash.js
fi
echoMessage "Saved to $file."
}
if [[ "$1" == "" ]]; then
#tip if no option
echoMessage "For more options see compile.sh -h."
else
#parse options
while [[ "$1" ]]; do
case $1 in
-d | --dry)
dry="true"
;;
-g | --git)
usehash="true"
;;
-h | --help)
displayHelp
exit 0
;;
-s | --sanity)
sanity="true"
;;
-q | --quiet)
output=/dev/null
;;
-t | --themes)
themes="true"
;;
-m | --minify)
minify="true"
;;
--ci)
ci="true"
;;
-f | --file)
name=$2
shift
;;
*)
echoError "Unknown argument $1."
displayHelp
exit 1
;;
esac
shift
done
fi
# Run sanity check.
[ -n "$sanity" ] && ./sanityCheck.sh
if ! [[ -d .git ]]; then
echoMessage "No git repository. Git specific actions disabled."
fi
#compile
if [[ "$dry" ]]; then
echoMessage "Dry run finished."
else
compile
echoMessage "Compilation finished at $(date +%T)."
fi
# compile themes
if [[ "$themes" ]]; then
(
cd themes/ || exit
for D in *; do
if [ -d "${D}" ]; then
../devTools/concatFiles.sh "${D}"/ '*.css' ../bin/"${D}".css
fi
done
)
echoMessage "Themes compiled at $(date +%T)"
fi