Allow to specify a directory and skip node_modules and tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
e49b6c576d
commit
e9f0a388d9
|
@ -1,16 +1,42 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
CHECK_DIR='../'
|
||||||
|
if ! [ "$SERVER_VERSION" ]; then
|
||||||
|
CHECK_DIR=$1
|
||||||
|
fi
|
||||||
|
|
||||||
function recursive_optimize_images() {
|
function recursive_optimize_images() {
|
||||||
cd "$1" || return
|
cd "$1" || return
|
||||||
|
DIR_NAME=${PWD##*/}
|
||||||
|
|
||||||
# Optimize all JPGs and PNGs
|
if [[ "$DIR_NAME" == "node_modules" ]]; then
|
||||||
optipng -o6 -strip all *.png
|
return
|
||||||
jpegoptim --strip-all *.jpg
|
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
|
# Optimize all SVGs
|
||||||
for svg in *.svg
|
for svg in *.svg
|
||||||
do
|
do
|
||||||
mv $svg $svg.opttmp;
|
[[ -e "$svg" ]] || break
|
||||||
|
|
||||||
|
mv $svg $svg.opttmp
|
||||||
scour --create-groups \
|
scour --create-groups \
|
||||||
--enable-id-stripping \
|
--enable-id-stripping \
|
||||||
--enable-comment-stripping \
|
--enable-comment-stripping \
|
||||||
|
@ -20,19 +46,19 @@ function recursive_optimize_images() {
|
||||||
--no-line-breaks \
|
--no-line-breaks \
|
||||||
-i $svg.opttmp \
|
-i $svg.opttmp \
|
||||||
-o $svg
|
-o $svg
|
||||||
|
rm $svg.opttmp
|
||||||
done
|
done
|
||||||
|
|
||||||
# Remove temporary SVGs
|
|
||||||
rm *.opttmp
|
|
||||||
|
|
||||||
# Check all subfolders
|
# Check all subfolders
|
||||||
for dir in */
|
for dir in */
|
||||||
do
|
do
|
||||||
if [[ -d "$DIR" ]]; then
|
[[ -e "$dir" ]] || break
|
||||||
|
|
||||||
|
if [[ -d "$dir" ]]; then
|
||||||
recursive_optimize_images "$dir"
|
recursive_optimize_images "$dir"
|
||||||
cd ..
|
cd ..
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
recursive_optimize_images ../
|
recursive_optimize_images "$CHECK_DIR"
|
||||||
|
|
Loading…
Reference in New Issue