-
Notifications
You must be signed in to change notification settings - Fork 25
/
compile
executable file
·409 lines (307 loc) · 9.79 KB
/
compile
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#!/bin/bash
echo "Builing Lite Client ($1 $2)"
echo ""
echo " Updating build number in options file"
currentTime=$(date +%s)
echo " Current Timestamp: $currentTime"
buildJsonFile="./config/build.json"
if [ ! -f "$buildJsonFile" ]; then
echo " build.json not found, creating file..."
mkdir -p ./config
echo '{"build_number": "0"}' > "$buildJsonFile"
fi
echo " Consolidating CSS files"
echo ""
for d in mods/*/ ;
do
if [ -d "$d"/web/css ]; then
if [ "$1" == "dev" ] || [ "$2" == "dev" ]; then
echo "link module css in $d"
find "$d"web/css/ -type f -name '*.css' 2>/dev/null | sed 's/mods.*web\///' | sed 's/^/@import url(".\//' | sed 's/$/");/' > "$d"web/style.css
else
echo "compile module css in $d"
echo "/**/" > "$d"web/style.css
echo "/* THIS FILE AUTOGENERATED FROM CSS in ./web/css/ */ " >> "$d"web/style.css
echo "/**/" >> "$d"web/style.css
find "$d"web/css -type f -name '*.css' -exec cat {} \; >> "$d"web/style.css
fi
fi
done
echo ""
if [ "$1" == "dev" ] || [ "$2" == "dev" ]; then
echo "linking game-*.css files into game.css"
find ./web/saito/ -type f -name 'game-*.css' | sed 's/\.\/web/@import url("/' | sed 's/$/");/' > ./web/saito/game.css
echo "linking saito-*.css files into saito.css"
find ./web/saito/ -type f -name 'saito-*.css' | sed 's/\.\/web/@import url("/' | sed 's/$/");/' > ./web/saito/saito.css
echo "@import url(\"/saito/css-imports/xclose.css\");" >> ./web/saito/saito.css;
else
echo "compiling game-*.css files into game.css"
echo "/**/" > ./web/saito/game.css
echo "/* THIS FILE AUTOGENERATED FROM CSS in saito/css-includes/ / */ " >> ./web/saito/game.css
echo "/**/" >> ./web/saito/game.css
find ./web/saito/ -type f -name 'game-*.css' -exec cat {} \; >> ./web/saito/game.css
echo "compiling saito-*.css files into saito.css"
echo "/**/" > ./web/saito/saito.css
echo "/* THIS FILE AUTOGENERATED FROM CSS in saito/css-includes/ / */ " >> ./web/saito/saito.css
echo "/**/" >> ./web/saito/saito.css
find ./web/saito/ -type f -name 'saito-*.css' -exec cat {} \; >> ./web/saito/saito.css
cat ./web/saito/css-imports/xclose.css >> ./web/saito/saito.css
fi
echo ""
echo "CSS complete"
echo ""
if [ "$1" == "dev" ] || [ "$2" == "dev" ]; then
echo ""
echo "Dev build - don't update build number"
echo ""
else
echo ""
echo "Updating Build Number"
currentTime=$(date +%s)
echo '{"build_number": "'$currentTime'"}' > ./config/build.json
cat ./config/build.json | sed 's/_/\ /' | sed 's/[{}"]//g'
echo ""
fi
function post_compile {
cp ./lib/saito/boot.js ./web/saito/saito2.js
cat ./web/saito/saito.js >> ./web/saito/saito2.js
mv -f ./web/saito/saito2.js ./web/saito/saito.js
echo -e "\ndone!"
}
function reset_bundler {
echo "Resetting Saito to Default Modules!"
echo ""
rm -rf ./bundler
if [ ! -d "./bundler" ]; then
mkdir -p bundler/default/mods
mkdir -p data/blocks
cp -rf ./lib bundler/default/lib
rm -f bundler/default/lib/saito/*.spec.js
rm -f bundler/default/lib/saito/core/*.spec.js
cp -rf ./config bundler/default/config
cp -rf ./apps bundler/default/apps
copy_lite_mods_to_bundler_directory
echo ""
echo "Compiling Lite-Client JS..."
rm -rf bundler/default/mods/appstore/bundler/dist
for md in bundler/default/mods/* ; do
rm -rf "$md/web"
rm -rf "$md/sql"
rm -rf "$md/www"
rm -rf "$md/src"
rm -rf "$md/docs"
rm -rf "$md/compile"
rm -rf "$md/DESCRIPTION.txt"
rm -rf "$md/BUGS.txt"
rm -rf "$md/README.txt"
rm -rf "$md/*.md"
rm -rf "$md/README.md"
rm -rf "$md/install.sh"
rm -rf "$md/license"
done
fi
}
function reset_nonpersistent {
mkdir -p data/blocks
# ensure deleted
rm -f ./web/saito/saito.js
# backup dbs before deleting anything
mkdir -p ./data/backup
cp -v ./data/*.sq3 ./data/backup/
# we explicitly don't delete registry/balance databases
rm -f ./data/appstore.sq3
rm -f ./data/arcade.sq3
rm -f ./data/records.sq3
rm -f ./data/timeclock.sq3
rm -f ./data/earlybirds.sq3
rm -f ./data/escrow.sq3
rm -f ./data/log.txt
rm -f ./data/*.sq3-journal
find ./data/blocks/ -name '*.sai' | xargs rm -r
rm -f ./data/shashmaps/*.smap
rm -f ./data/blocks/*.zip
rm -f ./data/blocks/*.segadd
rm -f ./data/tmp/*.sai
rm -f ./data/tmp/*.zip
rm -f ./config/options
rm -rf ./mods/appstore/mods
mkdir ./mods/appstore/mods
#
# do not delete compiled software
#
# rm -rf ./mods/appstore/bundler/dist/
rm -f ./mods/registry/web/addresses.txt
rm -f ./mods/appstore/mods/*
rm -rf ./mods/appstore/bundler/mods/*
rm -rf ./mods/appstore/bundler/dist/*
rm -f ./mods/appstore/bundler/*.js
rm -f ./mods/appstore/bundler/*.json
rm -f ./logs/*
#let the system know that users pre-existed a reset.
if [ -f ./data/rewards.sq3 ]; then
echo "update users set latest_tx = -1;" | sqlite3 ./data/rewards.sq3
fi
if [ ! -f ./config/modules.config.js ]; then
echo "copying modules from default list"
echo ""
cp ./config/modules.default.js ./config/modules.config.js
fi
if [ -f ./config/options.conf ]; then
echo "copying options from defaults"
cp ./config/options.conf ./config/options
else
cp ./config/options.conf.template ./config/options
fi
}
function reset_persistent {
# backup dbs before deleting anything
mkdir -p ./data/backup
cp -v ./data/*.sq3 ./data/backup/
# rm -f ./data/post.sq3
# rm -f ./data/arcade.sq3
# rm -f ./data/archive.sq3
rm -f ./data/registry.sq3
rm -f ./data/league.sq3
rm -f ./data/tutorial.sq3
rm -f ./web/client.options
mkdir -p data/blocks
}
function copy_lite_mods_to_bundler_directory {
PMOD=0
declare -a ARRAY_OF_MODS
input="./config/modules.config.js"
while IFS= read -r line
do
if [[ $PMOD == 1 ]]; then
if ! [[ $line == *"//"* ]]; then
#SUBSTRING=$(echo $line| cut -d".*/" -f 2)
#SUBSTRING2=$(echo $SUBSTRING| cut -d".js" -f 1)
SUBSTRING=$(echo $line | sed 's/.*\///')
SUBSTRING2=$(echo $SUBSTRING | sed 's/.js.*//')
if ! [[ $SUBSTRING2 == *"]"* ]]; then
if ! [[ $SUBSTRING2 == *"}"* ]]; then
ARRAY_OF_MODS+=($SUBSTRING2)
fi
fi
fi
fi
if [[ $line == *"lite"* ]]; then
PMOD=1
fi
done < $input
#printf '%s\n' "${ARRAY_OF_MODS[@]}"
for i in "${ARRAY_OF_MODS[@]}"; do
echo "installing mod for lite-client bundling: $i";
cp -rf ./mods/$i bundler/default/mods/$i
done
rm -f ./bundler/default/mods/appstore/mods/*
rm -f ./bundler/default/mods/appstore/bundler/*
rm -f ./bundler/default/mods/appstore/dist/*
}
if [ "$1" == "init" ]; then
if [ -f config/modules.config.js ]; then
echo "";
echo "It looks like you have already installed Saito. If you are "
echo "trying to change the modules that are installed on your "
echo "machine you can edit the file: "
echo "";
echo " config/modules.config.js";
echo "";
echo "And run the following command: ";
echo "";
echo " > npm run compile";
echo "";
echo "Continuing with this installation will delete existing data,"
echo "reset your wallet and resync the blockchain. Are you sure "
echo "you wish to continue? (yes/no)"
while true; do
read -p "> " yn
case $yn in
yes* ) cp config/modules.default.js config/modules.config.js; break;;
no* ) exit;;
* ) echo 'Please answer "yes" or "no".';;
esac
done
elif [ -f config/modules.default.js ]; then
echo "";
echo "Installing and compiling Saito with default modules..."
echo "";
fi
if [ -f config/saito.io.conf ]; then
while true; do
echo ""
echo "You can join the Saito Network and participate in development"
echo "of the public chain. Or you can setup a local node for the"
echo "easier development and testing of applications."
echo "";
echo "Join saito.io (saito) or local install (local): ";
read -p "> " yn
case $yn in
saito* ) cp config/saito.io.conf config/options; break;;
local* ) break;;
* ) echo 'Please answer "saito" or "local".';;
esac
done
fi
fi
if [ "$1" == "nuke" ] || [ "$1" == "init" ]; then
echo ""
echo ""
echo " _.-^^---....,,-- "
echo " _-- --_ "
echo " < >) "
echo " | | "
echo " \._ _./ "
echo " '''--. . , ; .--''' "
echo " | | | "
echo " .-=|| | |=-. "
echo " -=#$%&%$/=-' "
echo " | ; :| "
echo " .,-#%&$/#@%#&#~, "
echo " ------------------------- "
echo " NUKING YOUR SAITO INSTALL "
echo " ------------------------- "
echo " (resetting configuration) "
echo ""
echo ""
rm -rf built/*
tsc
reset_nonpersistent
reset_persistent
reset_bundler
time node webpack/webpack.config.cjs $2 $3
post_compile
fi
if [ "$1" == "reset" ] || [ "$1" == "dev" ]; then
echo ""
echo ""
echo " -------------------------- "
echo " RESETTING ALL BUT CORE DATA "
echo " -------------------------- "
echo " (resetting blockchain) "
echo ""
echo ""
tsc
reset_nonpersistent
reset_bundler
time node webpack/webpack.config.cjs $2 $3
post_compile
fi
if [ "$1" == "recompile" ]; then
echo ""
echo " ------------------------- "
echo " RE-COMPILING JAVASCRIPT "
echo " ------------------------- "
echo " (resetting configuration) "
echo ""
echo ""
# making sure we have some modules defined.
if [ ! -f ./config/modules.config.js ]; then
echo "copying modules from default list"
echo ""
cp ./config/modules.default.js ./config/modules.config.js
fi
reset_bundler
time node webpack/webpack.config.cjs $2 $3
post_compile
fi