Replace bash commands with proper svgo cli

Although this adds another requirement to execute this script, it will prevent OS-specific issues on `sed` and `grep` as described in #1503, and make sure anyone can generate the same SVG output files.

`--pretty` is kept for convenience but can be removed if needed.
pull/1506/head
Simon Marquis 6 months ago committed by GitHub
parent 85129e4660
commit 56b9871fae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -31,6 +31,14 @@ then
exit 1 exit 1
fi fi
# Check if the svgo command is available
if ! command -v svgo &> /dev/null
then
echo "The 'svgo' command is not found. This is required to cleanup and compress SVGs."
echo "Installation instructions available at https://github.com/svg/svgo."
exit 1
fi
# Check for a version of grep which supports Perl regex. # Check for a version of grep which supports Perl regex.
# On MacOS the OS installed grep doesn't support Perl regex so check for the existence of the # On MacOS the OS installed grep doesn't support Perl regex so check for the existence of the
# GNU version instead which is prefixed with 'g' to distinguish it from the OS installed version. # GNU version instead which is prefixed with 'g' to distinguish it from the OS installed version.
@ -114,10 +122,9 @@ echo "$module_paths" | while read -r module_path; do
-Pmodules.graph.of.module="${module_path}" </dev/null -Pmodules.graph.of.module="${module_path}" </dev/null
# Convert to SVG using dot, remove unnecessary comments, and reformat # Convert to SVG using dot, remove unnecessary comments, and reformat
dot -Tsvg "/tmp/${file_name}.gv" | dot -Tsvg "/tmp/${file_name}.gv" > "docs/images/graphs/${file_name}.svg"
sed 's/<!--/\x0<!--/g;s/-->/-->\x0/g' | grep -zv '^<!--' | tr -d '\0' | # Compress and cleanup SVG file
xmllint --format - \ svgo --multipass --pretty "docs/images/graphs/${file_name}.svg"
> "docs/images/graphs/${file_name}.svg"
# Remove the temporary .gv file # Remove the temporary .gv file
rm "/tmp/${file_name}.gv" rm "/tmp/${file_name}.gv"
fi fi

Loading…
Cancel
Save