-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild-frontend-desktop-app.sh
More file actions
executable file
·170 lines (151 loc) · 5.29 KB
/
build-frontend-desktop-app.sh
File metadata and controls
executable file
·170 lines (151 loc) · 5.29 KB
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
#!/bin/bash
# Usage:
# ./build-frontend-desktop-app.sh [--disable | --unset-SLOBS_NO_SIGN | --unset-all | --compile | --reload-zshrc]
# Arguments:
# --unset-SLOBS_NO_SIGN to remove SLOBS_NO_SIGN environment var so you can run codesign
# --unset-all to remove both SLOBS_NO_NOTARIZE & SLOBS_NO_SIGN environment variables
# --disable to bypass codesign completely (even if you have APPLE_SLD_IDENTITY set in your environment)
# --reload-zshrc: reload env vars from .zshrc
# --compile: runs yarn compile in the desktop folder
# Example: ./build-frontend-desktop-app.sh --compile --arch=arm64
function display_usage {
echo "Usage: $(basename "$0") [OPTIONS]"
echo ""
echo "Description: This script builds the Streamlabs Desktop.app on MacOS."
echo ""
echo "Options:"
echo " -h, --help Display this help message and exit."
echo " --unset-SLOBS_NO_SIGN remove SLOBS_NO_SIGN environment var"
echo " --unset-all remove both SLOBS_NO_NOTARIZE & SLOBS_NO_SIGN environment variables"
echo " --disable bypass codesign completely (even if you have APPLE_SLD_IDENTITY set in your environment)"
echo " --reload-zshrc reload env vars from .zshrc"
echo " --compile runs yarn compile in the desktop folder"
echo " --arch sets ARCH to arm64 or x86_64. Defaults to current machine arch."
echo " -o, --open run desktop from terminal"
echo " -c, --clean wipe cached node modules"
echo ""
echo "Examples:"
echo " $(basename "$0") --clean --arch=arm64"
echo ""
echo "Exit Status:"
echo " 0 on successful execution."
echo " 1 if Streamlabs desktop folder cannot be found."
exit 0
}
if [[ ( "$1" == "--help" ) || ( "$1" == "-h" ) ]]; then
display_usage
exit 0
fi
# Determine the operating system
ostype=$(uname)
if [ "$ostype" != "Darwin" ]; then
echo "Error: This script is intended to run on macOS only."
exit 1
fi
if [ ! -d "../desktop" ]; then
echo "Error: 'desktop' directory is not found."
exit 1
fi
ARCH=$(uname -m)
shouldOpen=false
shouldClean=false
shouldCompile=false
# function setups codesign/notarize
codesign_app() {
for arg in "$@"; do
# The settings below should come from the bash profile ideally.
if [[ "$arg" == "--disable" ]]; then
export SLOBS_NO_SIGN="true"
echo "$0 Set SLOBS_NO_SIGN=true to disable codesign"
elif [[ "$arg" == "--unset-SLOBS_NO_SIGN" ]]; then
unset SLOBS_NO_SIGN
echo "$0 unset SLOBS_NO_SIGN env var"
elif [[ "$arg" == "--unset-all" ]]; then
unset SLOBS_NO_NOTARIZE
unset SLOBS_NO_SIGN
echo "$0 unset SLOBS_NO_SIGN & SLOBS_NO_NOTARIZE env vars"
fi
done
}
origin_dir=$(dirname "$(realpath "$0")")
parent_dir=$(dirname "$origin_dir")
app_dir="$parent_dir"/desktop/node_modules/obs-studio-node/OSN.app
found_app=false
"./remove-DSStore.sh" # remove hidden files that will break codesign
if [ -d "$app_dir" ]; then
echo "backup OSN.app in $app_dir"
mkdir "$origin_dir"/tmp
mv $app_dir "$origin_dir"/tmp
rm -rf $app_dir
found_app=true
fi
# Search args for reload zsh option
for arg in "$@"; do
if [ "$arg" == "--reload-zshrc" ]; then
echo "$0 run source ~/.zshrc"
source ~/.zshrc
elif [[ $arg == --arch=* ]]; then
# Extract the value using parameter expansion
ARCH="${arg#*=}"
export ARCH="$ARCH"
elif [[ "$arg" == "--clean" || "$arg" == "-c" ]]; then
shouldClean=true
elif [[ "$arg" == "--open" || "$arg" == "-o" ]]; then
shouldOpen=true
elif [ "$arg" == "--compile" ]; then
shouldCompile=true
fi
done
codesign_app "$@"
cd "$origin_dir"
cd ../desktop
if [[ "$shouldClean" == true ]]; then
rm -rf ../desktop/node_modules
npm_config_arch=$ARCH
if [[ "$ARCH" == "x86_64" ]]; then
npm_config_arch="x64"
fi
echo "$0 run arch -$ARCH node -v"
arch -$ARCH node -v
exit_status=$?
if [ $exit_status -ne 0 ]; then
echo "Error: installed node does not match the desired architecture. See: https://gist.github.com/LeZuse/bf838718ff2689c5fc035c5a6825a11c"
exit 1
fi
echo "$0 run npm_config_arch=$npm_config_arch yarn install"
npm_config_arch=$npm_config_arch yarn install
echo "$0 run yarn compile"
yarn compile
elif [[ "$shouldCompile" == true ]]; then
echo "$0 run yarn compile"
yarn compile
fi
# set PYTHON_PATH to get around this issue: https://github.com/electron-userland/electron-builder/issues/6726
echo "$0 searching for python2 to resolve electron-builder issue: https://github.com/electron-userland/electron-builder/issues/6726"
output=$(which python2)
export PYTHON_PATH=$output
rm -rf dist # remove previous artifacts
if [[ "$ARCH" == "arm64" ]]; then
echo "$0 run yarn package:mac-arm64"
yarn package:mac-arm64
elif [[ "$ARCH" == "x86_64" ]]; then
echo "$0 run yarn package:mac"
yarn package:mac
fi
if [[ "$found_app" == "true" ]]; then
echo "Restore $app_dir"
mv "$origin_dir"/tmp/OSN.app $app_dir
rm -rf "$origin_dir"/tmp
fi
exit_status=$?
if [ $exit_status -eq 0 ]; then
if [[ "$shouldOpen" == true ]]; then
if [[ "$ARCH" == "arm64" ]]; then
cd dist/mac-arm64
elif [[ "$ARCH" == "x86_64" ]]; then
cd dist/mac-x86_64
fi
# Run the app directly so we can capture stdout and skip auto-updater
./Streamlabs\ Desktop.app/Contents/MacOS/Streamlabs\ Desktop --skip-update --nosync
fi
fi