-
Notifications
You must be signed in to change notification settings - Fork 20
/
zipFiles.sh
executable file
·80 lines (57 loc) · 2.02 KB
/
zipFiles.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
#!/bin/bash
set -e
MANIFEST="manifest.json"
BIN_DIR="./bin"
log_message() {
local message="$1"
local timestamp
timestamp=$(date +"%Y-%m-%d %H:%M:%S")
echo "[$timestamp] $message"
}
log_message "Copy readme to docs. Readme.md"
cp README.md docs/readme/README.md
log_message "----------------------"
log_message "Starting zip creation process"
if [ ! -d "$BIN_DIR" ]; then
log_message "Creating bin directory..."
mkdir -p "$BIN_DIR"
fi
if [ -d "$BIN_DIR" ]; then
# delete all files and subdirectories in the directory
log_message "deleting zip files from bin directory..."
rm -rf "$BIN_DIR"/*
fi
create_zip() {
local manifest_file="$1"
local output_zip="$2"
log_message "Creating ZIP using $manifest_file..."
name=""
version=""
while IFS='' read -r line || [[ -n "$line" ]]; do
if [[ "$line" == *"\"name\":"* ]]; then
name=$(echo "$line" | awk -F'"' '{print $4}')
elif [[ "$line" == *"\"version\":"* ]]; then
version=$(echo "$line" | awk -F'"' '{print $4}' | tr -d ',')
fi
done < "$manifest_file"
name="${name//,/}"
name="${name// /_}"
exclusions=("./docs/*" ".DS_Store" "*.json_*" "./node_modules" "./images/v[1-3]/*" "*.sh" "./bin" "./bin/*" "*.json_*" "./.*")
exclude_args=()
for pattern in "${exclusions[@]}"; do
exclude_args+=(-o -path "$pattern")
done
exclude_args=( "${exclude_args[@]:1}" )
files_to_zip=$(find . -type f ! \( "${exclude_args[@]}" \))
if [ -z "$files_to_zip" ]; then
log_message "No files found to zip for $version_name. Exiting."
exit 1
fi
echo "$files_to_zip" | zip -@ "$BIN_DIR/$output_zip"
log_message "ZIP file created: $BIN_DIR/$output_zip"
}
manifest_version=$(jq -r '.manifest_version' manifest.json)
# version=$(jq -r '.version' manifest.json)
echo "Manifest version is: $manifest_version"
create_zip "$MANIFEST" "CPI_Helper_Extension_manifestv${manifest_version}.zip"
log_message "Both CPI_Helper_Extension_v3.zip and moved to bin."