diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-05-21 09:48:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-21 09:48:55 +0200 |
commit | bd0a1b6e7d19d5f82b689bf7f04411290c552ec2 (patch) | |
tree | d7b198c0538e6e83cb0c83c636be86608259d6ce /build | |
parent | 1c1b349473e35c6335776e73f7b8fa7838fd9492 (diff) | |
parent | e9f0a388d93a06cfa6653ad5cdadc02f7c5373c2 (diff) | |
download | nextcloud-server-bd0a1b6e7d19d5f82b689bf7f04411290c552ec2.tar.gz nextcloud-server-bd0a1b6e7d19d5f82b689bf7f04411290c552ec2.zip |
Merge pull request #20586 from nextcloud/techdebt/noid/make-image-optimization.sh-better-readable
Improve build/image-optimization.sh
Diffstat (limited to 'build')
-rwxr-xr-x | build/image-optimization.sh | 74 |
1 files changed, 59 insertions, 15 deletions
diff --git a/build/image-optimization.sh b/build/image-optimization.sh index a1be5d22ce1..81866a0fee4 100755 --- a/build/image-optimization.sh +++ b/build/image-optimization.sh @@ -1,20 +1,64 @@ #!/usr/bin/env bash +CHECK_DIR='../' +if ! [ "$SERVER_VERSION" ]; then + CHECK_DIR=$1 +fi + function recursive_optimize_images() { -cd $1; -optipng -o6 -strip all *.png; -jpegoptim --strip-all *.jpg; -for svg in `ls *.svg`; -do - mv $svg $svg.opttmp; - scour --create-groups --enable-id-stripping --enable-comment-stripping --shorten-ids --remove-metadata --strip-xml-prolog --no-line-breaks -i $svg.opttmp -o $svg; -done; -rm *.opttmp -for dir in `ls -d */`; -do - recursive_optimize_images $dir; - cd ..; -done; + cd "$1" || return + DIR_NAME=${PWD##*/} + + if [[ "$DIR_NAME" == "node_modules" ]]; then + return + elif [[ "$DIR_NAME" == "tests" ]]; then + return + fi + + # Optimize all PNGs + for png in *.png + do + [[ -e "$png" ]] || break + + optipng -o6 -strip all "$png" + done + + # Optimize all JPGs + for jpg in *.jpg + do + [[ -e "$jpg" ]] || break + + jpegoptim --strip-all "$jpg" + done + + # Optimize all SVGs + for svg in *.svg + do + [[ -e "$svg" ]] || break + + mv $svg $svg.opttmp + scour --create-groups \ + --enable-id-stripping \ + --enable-comment-stripping \ + --shorten-ids \ + --remove-metadata \ + --strip-xml-prolog \ + --no-line-breaks \ + -i $svg.opttmp \ + -o $svg + rm $svg.opttmp + done + + # Check all subfolders + for dir in */ + do + [[ -e "$dir" ]] || break + + if [[ -d "$dir" ]]; then + recursive_optimize_images "$dir" + cd .. + fi + done } -recursive_optimize_images ../ +recursive_optimize_images "$CHECK_DIR" |