mirror of https://github.com/zulip/zulip.git
63 lines
1.5 KiB
Bash
Executable File
63 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
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
|
|
exit 1
|
|
fi
|
|
|
|
ZULIP_PATH="$(readlink -f "$(dirname "$0")"/../..)"
|
|
PNPM="/usr/local/bin/pnpm"
|
|
FILE_PATH="static/images/integrations/logos"
|
|
|
|
if [ -n "$CHECK_UNOPTIMIZED" ]; then
|
|
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"
|
|
if [ "$RESULT" -ge 1 ]; then
|
|
echo "ERROR: svgo detected unoptimized SVG file(s)." 1>&2
|
|
echo "Please run tools/setup/optimize-svg and commit the file changes to optimize them."
|
|
exit 1
|
|
else
|
|
echo "SUCCESS: SVG file(s) are optimized!"
|
|
fi
|
|
else
|
|
"$PNPM" exec svgo -q -f "$FILE_PATH"
|
|
"$ZULIP_PATH"/tools/setup/generate_integration_bots_avatars.py
|
|
fi
|