aboutsummaryrefslogtreecommitdiffstats
path: root/build/image-optimization.sh
diff options
context:
space:
mode:
Diffstat (limited to 'build/image-optimization.sh')
-rwxr-xr-xbuild/image-optimization.sh65
1 files changed, 61 insertions, 4 deletions
diff --git a/build/image-optimization.sh b/build/image-optimization.sh
index 6d494b8ddb7..ddb213ea5bb 100755
--- a/build/image-optimization.sh
+++ b/build/image-optimization.sh
@@ -1,4 +1,34 @@
#!/usr/bin/env bash
+#
+# SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+# SPDX-License-Identifier: AGPL-3.0-or-later
+#
+set -e
+
+OPTIPNG=$(which optipng)
+if ! [ -x "$OPTIPNG" ]; then
+ echo -e "\033[0;31moptipng executable not found, please install\033[0m" >&2
+ exit 1
+fi
+JPEGOPTIM=$(which jpegoptim)
+if ! [ -x "$JPEGOPTIM" ]; then
+ echo -e "\033[0;31mjpegoptim executable not found, please install\033[0m" >&2
+ exit 2
+fi
+SCOUR=$(which scour)
+if ! [ -x "$SCOUR" ]; then
+ echo -e "\033[0;31mscour executable not found, please install\033[0m" >&2
+ exit 3
+fi
+
+REQUIRED_SCOUR_VERSION="0.38.2"
+SCOUR_VERSION=$(scour --version)
+if dpkg --compare-versions $SCOUR_VERSION lt $REQUIRED_SCOUR_VERSION; then
+ echo "scour version $REQUIRED_SCOUR_VERSION or higher is required, found $SCOUR_VERSION" >&2
+ exit 3
+fi
+
+set +e
CHECK_DIR='../'
if [[ -d "$1" ]]; then
@@ -9,9 +39,26 @@ function recursive_optimize_images() {
cd "$1" || return
DIR_NAME=${PWD##*/}
- if [[ "$DIR_NAME" == "node_modules" ]]; then
+ if [[ "$DIR_NAME" == "3rdparty" ]]; then
+ echo -e "\033[0;36mIgnoring 3rdparty for image optimization\033[0m"
+ return
+ elif [[ "$DIR_NAME" == "build" ]]; then
+ echo -e "\033[0;36mIgnoring build for image optimization\033[0m"
+ return
+ elif [[ "$DIR_NAME" == "cypress" ]]; then
+ echo -e "\033[0;36mIgnoring cypress for image optimization\033[0m"
+ return
+ elif [[ "$DIR_NAME" == "node_modules" ]]; then
+ echo -e "\033[0;36mIgnoring node_modules for image optimization\033[0m"
return
elif [[ "$DIR_NAME" == "tests" ]]; then
+ echo -e "\033[0;36mIgnoring tests for image optimization\033[0m"
+ return
+ elif [[ "$DIR_NAME" == "vendor" ]]; then
+ echo -e "\033[0;36mIgnoring vendor for image optimization\033[0m"
+ return
+ elif [[ "$DIR_NAME" == "vendor-bin" ]]; then
+ echo -e "\033[0;36mIgnoring vendor-bin for image optimization\033[0m"
return
fi
@@ -20,7 +67,7 @@ function recursive_optimize_images() {
do
[[ -e "$png" ]] || break
- optipng -o6 -strip all "$png"
+ $OPTIPNG -o6 -strip all "$png"
done
# Optimize all JPGs
@@ -28,7 +75,7 @@ function recursive_optimize_images() {
do
[[ -e "$jpg" ]] || break
- jpegoptim --strip-all "$jpg"
+ $JPEGOPTIM --strip-all "$jpg"
done
# Optimize all SVGs
@@ -36,8 +83,13 @@ function recursive_optimize_images() {
do
[[ -e "$svg" ]] || break
+ if [[ "$svg" == "default-source.svg" ]]; then
+ echo -e "\033[0;36mIgnoring $svg image optimization\033[0m"
+ continue
+ fi
+
mv $svg $svg.opttmp
- scour --create-groups \
+ $SCOUR --create-groups \
--enable-id-stripping \
--enable-comment-stripping \
--shorten-ids \
@@ -55,6 +107,11 @@ function recursive_optimize_images() {
[[ -e "$dir" ]] || break
if [[ -d "$dir" ]]; then
+ if git check-ignore $dir -q ; then
+ echo -e "\033[0;36m$dir is not shipped. Ignoring image optimization\033[0m"
+ continue
+ fi
+
recursive_optimize_images "$dir"
cd ..
fi