2025-04-20 07:29:15 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Create necessary directories
|
2025-04-20 09:15:40 +08:00
|
|
|
echo "Creating necessary directories..."
|
2025-04-20 07:29:15 +08:00
|
|
|
mkdir -p dist/css
|
|
|
|
mkdir -p dist/js
|
|
|
|
mkdir -p dist/images
|
2025-05-28 19:09:33 +08:00
|
|
|
mkdir -p dist/openterface/firmware
|
2025-04-20 16:53:30 +08:00
|
|
|
cp src/CNAME dist/CNAME
|
2025-04-20 07:29:15 +08:00
|
|
|
|
2025-05-28 19:09:33 +08:00
|
|
|
# Copy all images and firmware to dist/images while preserving folder structure
|
2025-04-20 09:15:40 +08:00
|
|
|
echo "Copying images to dist/images..."
|
2025-04-20 07:29:15 +08:00
|
|
|
rsync -a src/images/ dist/images/
|
2025-05-28 19:09:33 +08:00
|
|
|
echo "Copying firmware to dist/openterface/firmware..."
|
|
|
|
rsync -a src/openterface/firmware/ dist/openterface/firmware/
|
2025-04-20 09:15:40 +08:00
|
|
|
echo "Images copied successfully."
|
2025-04-20 07:29:15 +08:00
|
|
|
|
2025-04-20 09:15:40 +08:00
|
|
|
# Generate a list of image files to convert to WebP
|
|
|
|
echo "Generating list of image files to convert to WebP..."
|
|
|
|
image_files=$(find src/images -type f \( -iname "*.png" -o -iname "*.jpg" -o -iname "*.jpeg" \))
|
|
|
|
echo "Image files to process:"
|
|
|
|
echo "$image_files"
|
|
|
|
|
|
|
|
# Convert images to WebP format
|
|
|
|
echo "Converting images to WebP format..."
|
|
|
|
for file in $image_files; do
|
2025-04-20 16:46:48 +08:00
|
|
|
target_dir="dist/images/$(dirname "$file" | sed "s|^src\/images||")"
|
2025-04-20 09:15:40 +08:00
|
|
|
mkdir -p "$target_dir"
|
2025-04-20 16:46:48 +08:00
|
|
|
echo "Processing image: $file -> $target_dir$(basename "${file%.*}.webp")"
|
2025-04-20 09:15:40 +08:00
|
|
|
cwebp "$file" -o "$target_dir/$(basename "${file%.*}.webp")"
|
|
|
|
done
|
|
|
|
|
|
|
|
# Generate a list of CSS files to minify
|
|
|
|
echo "Generating list of CSS files to minify..."
|
|
|
|
css_files=$(find src/css -type f -name "*.css")
|
|
|
|
echo "CSS files to process:"
|
|
|
|
echo "$css_files"
|
|
|
|
|
|
|
|
# Minify CSS files
|
|
|
|
echo "Minifying CSS files..."
|
|
|
|
for file in $css_files; do
|
2025-04-20 09:30:35 +08:00
|
|
|
echo "Input CSS file: $file"
|
2025-04-20 16:46:48 +08:00
|
|
|
target_dir="dist/css/$(dirname "$file" | sed "s|^src\/css||")"
|
2025-04-20 09:15:40 +08:00
|
|
|
mkdir -p "$target_dir"
|
2025-04-20 16:46:48 +08:00
|
|
|
output_file="$target_dir$(basename "${file%.css}.min.css")"
|
2025-04-20 09:30:35 +08:00
|
|
|
echo "Target directory: $target_dir"
|
|
|
|
echo "Output CSS file: $output_file"
|
|
|
|
csso "$file" -o "$output_file"
|
2025-04-20 09:15:40 +08:00
|
|
|
done
|
|
|
|
|
|
|
|
# Generate a list of JS files to minify
|
|
|
|
echo "Generating list of JS files to minify..."
|
|
|
|
js_files=$(find src/js -type f -name "*.js")
|
|
|
|
echo "JS files to process:"
|
|
|
|
echo "$js_files"
|
|
|
|
|
|
|
|
# Minify JS files
|
|
|
|
echo "Minifying JS files..."
|
|
|
|
for file in $js_files; do
|
2025-04-20 09:30:35 +08:00
|
|
|
echo "Input JS file: $file"
|
2025-04-20 13:12:07 +08:00
|
|
|
target_dir="dist/js/$(dirname "$file" | sed "s|^src\/js||")"
|
2025-04-20 09:15:40 +08:00
|
|
|
mkdir -p "$target_dir"
|
2025-04-20 16:46:48 +08:00
|
|
|
output_file="$target_dir$(basename "${file%.js}.min.js")"
|
2025-04-20 09:30:35 +08:00
|
|
|
echo "Target directory: $target_dir"
|
|
|
|
echo "Output JS file: $output_file"
|
|
|
|
uglifyjs "$file" -o "$output_file"
|
2025-04-20 09:15:40 +08:00
|
|
|
done
|
|
|
|
|
|
|
|
echo "Build process completed."
|