diff --git a/build.sh b/build.sh index beff2fa..5da5d70 100755 --- a/build.sh +++ b/build.sh @@ -5,10 +5,12 @@ cd "$(dirname "$0")" VERSION=$(node -p "require('./package.json').version") OUT="build/PLGL-$VERSION.tar.gz" +bash tools/svg2png.sh renderer/plgl.svg renderer/plgl.png 256 + rm -rf build/dist mkdir -p build/dist/PLGL build/files -cp -r src renderer files package.json build/dist/PLGL/ +cp -r src renderer tools files package.json build/dist/PLGL/ cp -r files/translations build/files/ 2>/dev/null || true if [ ! -d node_modules/electron/dist ]; then @@ -24,6 +26,7 @@ cat > build/dist/PLGL/run.sh << 'EOF' #!/usr/bin/env bash set -e cd "$(dirname "$0")" +bash tools/svg2png.sh renderer/plgl.svg renderer/plgl.png 256 exec ./node_modules/electron/dist/electron . "$@" EOF chmod +x build/dist/PLGL/run.sh diff --git a/run.sh b/run.sh index aad6053..259e0ae 100755 --- a/run.sh +++ b/run.sh @@ -7,6 +7,8 @@ if [ ! -d node_modules ]; then npm install fi +bash tools/svg2png.sh renderer/plgl.svg renderer/plgl.png 256 + mkdir -p build/files cp -r files/translations build/files/ 2>/dev/null || true diff --git a/tools/svg2png.sh b/tools/svg2png.sh new file mode 100644 index 0000000..289ea8c --- /dev/null +++ b/tools/svg2png.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# Convert an SVG file to a square PNG using whichever converter is available. +# Tries, in order: rsvg-convert, inkscape, magick, convert. +# Usage: svg2png.sh [size] +set -e + +in="$1" +out="$2" +size="${3:-256}" + +[ -f "$in" ] || { echo "svg2png: input not found: $in" >&2; exit 1; } + +if command -v rsvg-convert >/dev/null 2>&1; then + rsvg-convert -w "$size" -h "$size" -o "$out" "$in" && exit 0 +fi + +if command -v inkscape >/dev/null 2>&1; then + if inkscape --version 2>/dev/null | grep -Eq 'Inkscape 0\.'; then + inkscape -z "$in" -e "$out" -w "$size" -h "$size" && exit 0 + fi + inkscape "$in" --export-type=png --export-filename="$out" -w "$size" -h "$size" && exit 0 +fi + +if command -v magick >/dev/null 2>&1; then + magick -background none "$in" -resize "${size}x${size}" "$out" && exit 0 +fi + +if command -v convert >/dev/null 2>&1; then + convert -background none "$in" -resize "${size}x${size}" "$out" && exit 0 +fi + +echo "svg2png: no SVG converter found (install librsvg, inkscape or imagemagick)" >&2 +exit 1