-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
compile-all.sh
executable file
·133 lines (121 loc) · 4.3 KB
/
compile-all.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
#!/bin/bash
OUTPUT_RED='\033[0;31m' # red
OUTPUT_ORANGE='\033[0;33m' # orange
OUTPUT_GREEN='\033[0;32m' # green
OUTPUT_NC='\033[0m' # no color
echo
echo -e "${OUTPUT_ORANGE}Always check whether the dynamically included libraries (chartjs and showdownjs) are still up to date! ${OUTPUT_NC}"
echo
# run the unit tests
echo "Running unit tests"
npm run test
if [ $? -eq 0 ] # check the exit status of the last command
then
echo -e "|${OUTPUT_GREEN} unit tests passed ${OUTPUT_NC}"
else
echo -e "|${OUTPUT_RED} unit tests failed"
exit 1
fi
# bundle all scripts by replacing insert statements with file contents
echo
cd Scripts
echo "Bundling scripts"
/bin/bash bundle_scripts.sh
cd ..
# statically validate the syntax
echo "Statically validating bundled script"
validated=$(node --check bundled_script.js 2>&1)
if [ -z "$validated" ]
then
echo -e "|${OUTPUT_GREEN} valid ${OUTPUT_NC}"
else
echo -e "|${OUTPUT_RED} invalid bundled_script.js, reason:"
echo $validated
exit 1
fi
# minify the bundled_script.js file
echo "Minifying bundled script"
terser bundled_script.js --compress --output bundled_script.js # use --timings to see how long each step takes
echo
# Clean the binaries folder
rm -rf Binaries
mkdir Binaries
# Setup variables
echo
echo "--------"
name="--name Overleaf"
destination="Binaries/"
appversionnumber=$(cat Scripts/appversion.js | grep -o ".\..\..")
appversion="--app-version $appversionnumber"
epochtime=$(date +%s)
buildversion="--build-version $appversionnumber.$epochtime"
script="--inject bundled_script.js"
internalurls="--internal-urls .*?(login|profile|engine|auth|idp|identity|secure|sso|duosecurity|phonefactor|oauth|otpauth|signin|account.*)\..*?(?<TLD>\.\w+?)(?:$|\/)" # matches all *(login|profile|engine|auth|account.*|etc...).*.<top-level-domain> URLs until the first forward-slash, may be a too greedy because it will also match slugs (e.g. domain.com/login.file.html)
basecommand="nativefier https://overleaf.com $destination $name $appversion $buildversion $internalurls $script --user-agent-honest --overwrite --disable-old-build-warning-yesiknowitisinsecure"
# function to compile while filtering the nativefier output so only relevant output remains
function compile() {
# read in "named" arguments
_platform="--platform $1"
_arch="--arch $2"
_icon="--icon $3"
# read in remaining arguments as options string
shift 3
_options="${@:-""}"
echo "compiling with '$_platform $_arch $_icon $_options'"
# execute compilation while redirecting stdout and stderr to respective files
$basecommand $_platform $_arch $_icon $_options > out 2>error
if grep -iq ERROR error; # check if the error output contains "Error"
then
echo -e "|${OUTPUT_RED} failed to compile, reason: (check error file for details) ${OUTPUT_NC}"
cat error | grep -i ERROR
exit 1
fi
if grep -iq WARNING error; # check if the error output contains "Warning"
then
echo -e "|${OUTPUT_ORANGE} compiled with warnings, reason: (check error file for details) ${OUTPUT_NC}"
cat error | grep -i WARNING
exit 1
fi
# clean up the outputted files and argument list
rm error
rm out
shift $#
echo
}
# Mac
echo "Compiling for Mac"
platform="osx"
icon="Icons/Mac.icns"
options="--darwin-dark-mode-support --counter --bounce --fast-quit"
compile $platform "arm64" $icon $options
compile $platform "x64" $icon $options
echo "Codesigning Mac apps"
xattr -c Binaries/Overleaf-darwin-arm64/Overleaf.app
xattr -c Binaries/Overleaf-darwin-x64/Overleaf.app
codesign -s - -f --deep Binaries/Overleaf-darwin-arm64/Overleaf.app
codesign -s - -f --deep Binaries/Overleaf-darwin-x64/Overleaf.app
echo ""
# Linux
echo "Compiling for Linux"
platform="linux"
icon="Icons/base_icon.png"
compile $platform "arm64" $icon
compile $platform "armv7l" $icon
compile $platform "x64" $icon
# Windows
echo "Compiling for Windows"
platform="windows"
icon="Icons/Windows.ico"
compile $platform "arm64" $icon
compile $platform "x64" $icon
# Zipping
echo
echo "--------"
cd $destination
for d in */ ; do
target="${d%?}.zip" # remove the / at the end of the folder name
echo "Zipping $d to $target"
ditto -c -k --sequesterRsrc --keepParent $d $target
# zip -r -X -o $target $d # ditto is much more efficient for zipping Mac applications
done
cd ..