mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
I have made `tools/setup/optimize-svg` do the SVG optimization automatically rather than just telling you the command to run if they need optimizing. This included adding a `--check` parameter to use in CI to only check as we previously did rather than actually running the optimization. I have also made `tools/setup/optimize-svg` execute `tools/setup/generate_integration_bots_avatars.py` once it has run the optimization to ensure it is always ran. This makes it one less command to run when creating an integration, but also means that we catch instances where a PNG has just been copied into the `static/images/integrations/bot_avatars` folder as the only instance where this won't be run is if `optimize-svg` has not been run which would be caught in CI. Fixes #18183. Fixes #18184.
58 lines
1.4 KiB
Bash
Executable File
58 lines
1.4 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")"/../..)"
|
|
|
|
if [ -n "$CHECK_UNOPTIMIZED" ]; then
|
|
if [ "$(node_modules/.bin/svgo -f static/images/integrations/logos | grep -o '\.[0-9]% = ' | wc -l)" -ge 1 ]; then
|
|
echo "ERROR: svgo detected unoptimized SVG files in the \`static/images/integrations/logos\` folder." 1>&2
|
|
echo "Please run tools/setup/optimize-svg and commit the file changes to optimize them."
|
|
exit 1
|
|
else
|
|
echo "SUCCESS: SVG files in static/images/integrations/logos are all optimized!"
|
|
fi
|
|
else
|
|
yarn run svgo -q -f static/images/integrations/logos
|
|
"$ZULIP_PATH"/tools/setup/generate_integration_bots_avatars.py
|
|
fi
|