optimize-svg: The --check flag does not modify files anymore.

The `svgo` command needs to write to a file to process it.
So, create and use a mktemp path, and delete it after the svgo command.
This commit is contained in:
Niloth P 2024-11-18 13:02:58 +05:30 committed by Tim Abbott
parent 5b3d2a9e59
commit ef3fbcf954
1 changed files with 3 additions and 1 deletions

View File

@ -46,7 +46,9 @@ PNPM="/usr/local/bin/pnpm"
FILE_PATH="static/images/integrations/logos" FILE_PATH="static/images/integrations/logos"
if [ -n "$CHECK_UNOPTIMIZED" ]; then if [ -n "$CHECK_UNOPTIMIZED" ]; then
RESULT=$("$PNPM" exec svgo -f "$FILE_PATH" | grep -o '\.[0-9]% = ' | wc -l) 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 if [ "$RESULT" -ge 1 ]; then
echo "ERROR: svgo detected unoptimized SVG file(s)." 1>&2 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." echo "Please run tools/setup/optimize-svg and commit the file changes to optimize them."