summaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-04-21 13:50:26 +0200
committerJoas Schilling <coding@schilljs.com>2020-04-21 13:50:26 +0200
commite9f0a388d93a06cfa6653ad5cdadc02f7c5373c2 (patch)
tree619b9358b139b18f5d66fa2e13e368dffd37713e /build
parente49b6c576d524a2930c4b82e57e5c1e6da35bc6a (diff)
downloadnextcloud-server-e9f0a388d93a06cfa6653ad5cdadc02f7c5373c2.tar.gz
nextcloud-server-e9f0a388d93a06cfa6653ad5cdadc02f7c5373c2.zip
Allow to specify a directory and skip node_modules and tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'build')
-rwxr-xr-xbuild/image-optimization.sh44
1 files changed, 35 insertions, 9 deletions
diff --git a/build/image-optimization.sh b/build/image-optimization.sh
index 148f0c9695a..81866a0fee4 100755
--- a/build/image-optimization.sh
+++ b/build/image-optimization.sh
@@ -1,16 +1,42 @@
#!/usr/bin/env bash
+CHECK_DIR='../'
+if ! [ "$SERVER_VERSION" ]; then
+ CHECK_DIR=$1
+fi
+
function recursive_optimize_images() {
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 and PNGs
- optipng -o6 -strip all *.png
- jpegoptim --strip-all *.jpg
+ # Optimize all JPGs
+ for jpg in *.jpg
+ do
+ [[ -e "$jpg" ]] || break
+
+ jpegoptim --strip-all "$jpg"
+ done
# Optimize all SVGs
for svg in *.svg
do
- mv $svg $svg.opttmp;
+ [[ -e "$svg" ]] || break
+
+ mv $svg $svg.opttmp
scour --create-groups \
--enable-id-stripping \
--enable-comment-stripping \
@@ -20,19 +46,19 @@ function recursive_optimize_images() {
--no-line-breaks \
-i $svg.opttmp \
-o $svg
+ rm $svg.opttmp
done
- # Remove temporary SVGs
- rm *.opttmp
-
# Check all subfolders
for dir in */
do
- if [[ -d "$DIR" ]]; then
+ [[ -e "$dir" ]] || break
+
+ if [[ -d "$dir" ]]; then
recursive_optimize_images "$dir"
cd ..
fi
done
}
-recursive_optimize_images ../
+recursive_optimize_images "$CHECK_DIR"