forked from AstraExt/astra-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpack.sh
131 lines (106 loc) · 3.44 KB
/
pack.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
#!/bin/bash
# pack.sh - Script to package GNOME extension into a zip file for distribution
# Check for necessary tools
command -v bash >/dev/null 2>&1 || { echo >&2 "Bash is required but it's not installed. Aborting."; exit 1; }
command -v glib-compile-schemas >/dev/null 2>&1 || { echo >&2 "glib-compile-schemas is required but it's not installed. Aborting."; exit 1; }
# Function to log messages
log_message() {
echo "[`date +"%Y-%m-%d %H:%M:%S"`] $1"
}
# Paths and filenames
EXTENSION_DIR=$(dirname "$0") # Assumes pack.sh is in the main directory
DIST_DIR="${EXTENSION_DIR}/dist"
EXTENSION_NAME="[email protected]"
# Read VERSION from metadata.json
if [ -f "${EXTENSION_DIR}/metadata.json" ]; then
VERSION=$(grep '"version"' "${EXTENSION_DIR}/metadata.json" | grep -o '[0-9]*')
if [ -z "$VERSION" ]; then
log_message "Version not found in metadata.json"
exit 1
fi
else
log_message "metadata.json not found. Aborting."
exit 1
fi
# Run schemas.sh
if [ -f "${EXTENSION_DIR}/schemas.sh" ]; then
log_message "Running schemas.sh..."
bash "${EXTENSION_DIR}/schemas.sh" || { log_message "schemas.sh failed. Aborting."; exit 1; }
else
log_message "schemas.sh not found. Aborting."
exit 1
fi
# Remove the previous build if any
rm -rf "[email protected]"
# Clean up build directory
rm -r "build"
# Check if tsc is installed
command -v tsc >/dev/null 2>&1 || { log_message "Error: tsc is required but it's not installed. Aborting."; exit 1; }
# Compile TypeScript
log_message "Building typescript files..."
tsc
# Check for errors
if [ $? -ne 0 ]; then
log_message "Failed to compile TypeScript"
exit 1
fi
# Format the code
log_message "Formatting the code..."
npm run format
# Check for errors
if [ $? -ne 0 ]; then
log_message "Failed to format the code"
exit 1
fi
# Run i18n.sh
if [ -f "${EXTENSION_DIR}/i18n.sh" ]; then
log_message "Running i18n.sh..."
bash "${EXTENSION_DIR}/i18n.sh" || { log_message "i18n.sh failed. Aborting."; exit 1; }
else
log_message "i18n.sh not found. Aborting."
exit 1
fi
# Create dist directory
mkdir -p "$DIST_DIR"
# Copy build directory content to dist directory
cp -r "${EXTENSION_DIR}/build/"* "${DIST_DIR}/"
# Files and directories to include
INCLUDE_FILES="metadata.json stylesheet.css README.md RELEASES.md LICENSE schemas icons po"
# Copy files to dist directory
for file in $INCLUDE_FILES; do
if [ -e "${EXTENSION_DIR}/${file}" ]; then
cp -r "${EXTENSION_DIR}/${file}" "${DIST_DIR}/"
else
log_message "File or directory ${file} not found. Aborting."
rm -rf "$DIST_DIR"
exit 1
fi
done
# enter dist directory
cd "$DIST_DIR"
# Pack the extension
gnome-extensions pack --force \
--podir=./po \
--extra-source=./src \
--extra-source=./icons \
--extra-source=./LICENSE \
--extra-source=./README.md \
--extra-source=./RELEASES.md \
--extra-source=./ROADMAP.md \
--extra-source=./COMPARISON.md \
.
# Check for errors
if [ $? -ne 0 ]; then
log_message "Failed to pack the extension"
cd "${EXTENSION_DIR}"
rm -rf "${DIST_DIR}"
exit 1
fi
# Copy the packed extension to the main directory
mv "$EXTENSION_NAME.shell-extension.zip" "../$EXTENSION_NAME.shell-extension.zip"
# Return to the main directory
cd ..
# Clean up: remove the dist directory
rm -rf "${DIST_DIR}"
log_message "Extension packaged into $EXTENSION_NAME.shell-extension.zip"
exit 0