zulip/tools/setup/optimize-svg
Lalit 112df91fbd provision: Do not require that no other yarn precedes us in $PATH.
`check_version` in `install-yarn` had the rather careful check that
the yarn it installed into `/usr/bin/yarn` was the yarn which was
first in the user's `$PATH`.  This caused problems when the user had a
pre-existing `/usr/local/bin/yarn`; however, those problems are
limited to the `install-yarn` script itself, since the nearly all
calls to yarn from Zulip's code already hardcode the `/srv/zulip-yarn`
location, and do not depend on what is in `$PATH`.

Remove the checks in `install-yarn` that depend on the local `$PATH`,
and stop installing our `yarn` into it.  We also adjust the two
callsites which did not specify the full path to `yarn`, so use
`/srv/zulip-yarn`.

Fixes: #23993

Co-authored-by: Alex Vandiver <alexmv@zulip.com>
2023-01-19 17:51:52 -05:00

59 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")"/../..)"
YARN="/srv/zulip-yarn/bin/yarn"
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