Skip to content

Commit 399d9c9

Browse files
committed
add build / clean scripts + improve .gitignore
1 parent 4dd5232 commit 399d9c9

3 files changed

Lines changed: 126 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
.DS_STORE
2+
3+
dist/
4+
*.zip

scripts/build

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env zsh
2+
3+
# Capture script name
4+
SCRIPT_NAME=$0
5+
6+
# Variables
7+
DIST_DIR="dist"
8+
ITEMS_TO_COPY=("README.md" "LICENSE.md" "manifest.json" "src" "icons")
9+
EXTENSION_NAME="newWindowWithTabsToRight"
10+
11+
# Function to show help
12+
show_help() {
13+
echo "Usage: $SCRIPT_NAME [options]"
14+
echo "Options:"
15+
echo " -h, --help Show this help message"
16+
}
17+
18+
# Function to read version from manifest.json using jq
19+
read_version() {
20+
if ! command -v jq &> /dev/null; then
21+
echo "Error: jq is not installed."
22+
exit 1
23+
fi
24+
25+
VERSION=$(jq -r '.version' manifest.json)
26+
if [ -z "$VERSION" ]; then
27+
echo "Error: Could not read version from manifest.json"
28+
exit 1
29+
fi
30+
}
31+
32+
# Parse options
33+
while [[ "$#" -gt 0 ]]; do
34+
case $1 in
35+
-h|--help) show_help; exit 0;;
36+
*) echo "Unknown option: $1"; show_help; exit 1;;
37+
esac
38+
shift
39+
done
40+
41+
# Read version
42+
echo "Reading version from manifest.json..."
43+
read_version
44+
echo "Version: $VERSION"
45+
46+
# Create zip filename
47+
ZIP_FILE="${EXTENSION_NAME}-${VERSION}.zip"
48+
49+
# Create the dist directory
50+
echo "Creating dist directory..."
51+
mkdir -p $DIST_DIR
52+
53+
# Copy files and directories using rsync to exclude .DS_Store files
54+
echo "Copying files and directories..."
55+
for item in ${ITEMS_TO_COPY[@]}; do
56+
if [ -e $item ]; then
57+
rsync -a --exclude='.DS_Store' $item $DIST_DIR/
58+
echo " Copied: $item"
59+
else
60+
echo " Warning: $item does not exist."
61+
fi
62+
done
63+
64+
# Create zip file
65+
if [ -f $ZIP_FILE ]; then
66+
echo "Removing existing zip file: $ZIP_FILE"
67+
rm $ZIP_FILE
68+
fi
69+
70+
echo "Creating zip file: $ZIP_FILE"
71+
cd $DIST_DIR
72+
zip -r ../$ZIP_FILE ./*
73+
cd ..
74+
75+
echo "Build completed. Files are in the $DIST_DIR directory and zipped in $ZIP_FILE."

scripts/clean

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env zsh
2+
3+
# Capture script name
4+
SCRIPT_NAME=$0
5+
6+
# Variables
7+
DIST_DIR="dist"
8+
EXTENSION_NAME="newWindowWithTabsToRight"
9+
10+
# Function to show help
11+
show_help() {
12+
echo "Usage: $SCRIPT_NAME [options]"
13+
echo "Options:"
14+
echo " -h, --help Show this help message"
15+
}
16+
17+
# Parse options
18+
while [[ "$#" -gt 0 ]]; do
19+
case $1 in
20+
-h|--help) show_help; exit 0;;
21+
*) echo "Unknown option: $1"; show_help; exit 1;;
22+
esac
23+
shift
24+
done
25+
26+
# Remove the dist directory
27+
if [ -d ./$DIST_DIR ]; then
28+
echo "Removing dist directory: $DIST_DIR"
29+
rm -rf ./$DIST_DIR
30+
else
31+
echo "Dist directory does not exist: $DIST_DIR"
32+
fi
33+
34+
# Find and remove the zip files with NULL_GLOB enabled just for this line
35+
ZIP_FILES=($(setopt NULL_GLOB; echo ./${EXTENSION_NAME}-*.zip))
36+
37+
# Remove the zip files
38+
if [ ${#ZIP_FILES[@]} -gt 0 ]; then
39+
echo "Removing zip files:"
40+
for file in $ZIP_FILES; do
41+
echo " $file"
42+
rm -f "$file"
43+
done
44+
else
45+
echo "No zip files found matching: ${EXTENSION_NAME}-*.zip"
46+
fi
47+
48+
echo "Cleanup completed. $DIST_DIR directory and matching zip files in the current directory have been removed."

0 commit comments

Comments
 (0)