-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathinclude_ui.sh
executable file
·98 lines (78 loc) · 2.33 KB
/
include_ui.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
#!/usr/bin/env bash
UPDATE_FLAG=0
echo "Checking for required dependencies"
if ! command -v npm &> /dev/null
then
if ! command -v node &> /dev/null
then
echo ""
echo ""
echo "We couldn't find npm and NodeJS, however they are required for the ui"
echo "Install NodeJS with a package manager, or try using nvm (Node Version Manager)"
echo ""
echo "(should be at least version 20)"
exit
fi
NODE_VERSION=$( node --version )
echo ""
echo ""
echo "We couldn't find npm, but we found NodeJS ($NODE_VERSION)"
echo "Try looking for npm in your package manager"
echo ""
exit
fi
NODE_VERSION=$( node --version )
MAJOR_NODE_VERSION=$(echo "$NODE_VERSION" | cut -c "2-" | cut -c "-2")
if [ "$MAJOR_NODE_VERSION" -lt "20" ]; then
echo ""
echo ""
echo "Warning: NodeJS version lower than 20 (it is $NODE_VERSION)"
echo "This might cause errors during the build process"
echo ""
echo ""
fi
if ! command -v pnpm &> /dev/null
then
echo ""
echo "pnpm could not be found, install it? (Y/n)"
# Read without -r will mangle backslashes
read -r install_pnpm
if [[ $install_pnpm =~ ^([yY](es)?)?$ ]]
then
sudo npm i -g pnpm
else
exit
fi
fi
echo "Checking for UI repository"
if [ -e "ui/last_commit_hash.txt" ]; then
echo "Reading existing commit hash"
LAST_COMMIT_HASH=$(<ui/last_commit_hash.txt)
else
echo "last_commit_hash.txt not found, setting to empty"
LAST_COMMIT_HASH=""
fi
echo "Fetching latest commit hash from GitHub API"
GITHUB_HASH=$(curl -s https://api.github.com/repos/MegaAntiCheat/MegaAntiCheat-UI/git/refs/heads/main | grep sha | cut -d '"' -f 4)
if [ "$LAST_COMMIT_HASH" == "$GITHUB_HASH" ]; then
echo "No updates to the repository."
UPDATE_FLAG=1
fi
if [ "$UPDATE_FLAG" -eq 0 ]; then
echo "Removing old UI files"
rm -rf ui/*
touch ui/.gitkeep
rm -rf ui_temp
echo "Cloning and building UI"
git clone --filter=tree:0 https://github.com/MegaAntiCheat/MegaAntiCheat-UI ui_temp
echo "Saving last commit hash"
cd ui_temp || exit
git rev-parse HEAD > ../ui/last_commit_hash.txt
npm exec pnpm i
npm exec pnpm run build
mkdir -p ../ui/
cp dist/* ../ui/
echo "Removing temp files"
cd ..
rm -rf ui_temp
fi