2018-12-18 02:08:53 +01:00
|
|
|
#!/usr/bin/env bash
|
2021-04-16 23:33:35 +02:00
|
|
|
set -e
|
2017-05-23 00:11:08 +02:00
|
|
|
|
2021-04-16 23:33:35 +02:00
|
|
|
usage() {
|
|
|
|
cat <<'EOF'
|
|
|
|
Usage:
|
|
|
|
optimize-svg --check
|
|
|
|
optimize-svg --help
|
|
|
|
|
|
|
|
Options:
|
|
|
|
--check
|
|
|
|
This will check for unoptimized SVG files rather than automatically optimizing them.
|
|
|
|
This allows us to run the script in CI.
|
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
# Shell option parsing. Over time, we'll want to move some of the
|
|
|
|
# environment variables below into this self-documenting system.
|
|
|
|
args="$(getopt -o '' --long help,check -n "$0" -- "$@")"
|
|
|
|
eval "set -- $args"
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
|
|
|
--help)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
--check)
|
|
|
|
CHECK_UNOPTIMIZED=1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "$#" -gt 0 ]; then
|
|
|
|
usage >&2
|
2020-10-15 04:55:57 +02:00
|
|
|
exit 1
|
2021-04-16 23:33:35 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
ZULIP_PATH="$(readlink -f "$(dirname "$0")"/../..)"
|
2023-03-20 19:52:59 +01:00
|
|
|
PNPM="/usr/local/bin/pnpm"
|
2024-11-18 08:19:37 +01:00
|
|
|
FILE_PATH="static/images/integrations/logos"
|
2021-04-16 23:33:35 +02:00
|
|
|
|
|
|
|
if [ -n "$CHECK_UNOPTIMIZED" ]; then
|
2024-11-18 08:32:58 +01:00
|
|
|
TEMP_PATH=$(mktemp -d svgo_temp_XXXXXX)
|
|
|
|
RESULT=$("$PNPM" exec svgo -o "$TEMP_PATH" -f "$FILE_PATH" | grep -o '\.[0-9]% = ' | wc -l)
|
|
|
|
rm -rf "$TEMP_PATH"
|
2024-11-18 08:11:36 +01:00
|
|
|
if [ "$RESULT" -ge 1 ]; then
|
2024-11-18 08:19:37 +01:00
|
|
|
echo "ERROR: svgo detected unoptimized SVG file(s)." 1>&2
|
2021-04-16 23:33:35 +02:00
|
|
|
echo "Please run tools/setup/optimize-svg and commit the file changes to optimize them."
|
|
|
|
exit 1
|
|
|
|
else
|
2024-11-18 08:19:37 +01:00
|
|
|
echo "SUCCESS: SVG file(s) are optimized!"
|
2021-04-16 23:33:35 +02:00
|
|
|
fi
|
2020-10-15 04:55:57 +02:00
|
|
|
else
|
2024-11-18 08:19:37 +01:00
|
|
|
"$PNPM" exec svgo -q -f "$FILE_PATH"
|
2021-04-16 23:33:35 +02:00
|
|
|
"$ZULIP_PATH"/tools/setup/generate_integration_bots_avatars.py
|
2017-05-23 00:11:08 +02:00
|
|
|
fi
|