From 084b947e8d5160c429703065892a885af9520e90 Mon Sep 17 00:00:00 2001 From: Jonas Broms Date: Tue, 30 Nov 2021 21:13:59 +0100 Subject: [PATCH] Recreate the commitizen logo in png & svg format (#878) * Recreate the commitizen logo in png & svg format * refactor(logos): dynamically generate pngs from svg files re #800 * build(generate.sh): fix existance checking for cairosvg executable in build envs Co-authored-by: Dave Welch --- .gitignore | 3 +- jobs/build.yml | 1 + logo/commitizen-logo-color.svg | 5 ++ logo/commitizen-logo-mono.svg | 100 +++++++++++++++++++++++++++++++++ logo/generate.sh | 58 +++++++++++++++++++ 5 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 logo/commitizen-logo-color.svg create mode 100644 logo/commitizen-logo-mono.svg create mode 100644 logo/generate.sh diff --git a/.gitignore b/.gitignore index 118a0996..8673768e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ artifacts/ /dist npm-debug.log .nyc_output -test/tools/trigger-appveyor-tests.sh \ No newline at end of file +test/tools/trigger-appveyor-tests.sh +logo/*.png \ No newline at end of file diff --git a/jobs/build.yml b/jobs/build.yml index 18464a8c..3dfdda13 100644 --- a/jobs/build.yml +++ b/jobs/build.yml @@ -27,6 +27,7 @@ jobs: - script: npm install - script: npm run build - script: npm test && npm run write-coverage + - script: bash logo/generate.sh - task: PublishTestResults@2 displayName: 'Publish Test Results' inputs: diff --git a/logo/commitizen-logo-color.svg b/logo/commitizen-logo-color.svg new file mode 100644 index 00000000..0c2942b4 --- /dev/null +++ b/logo/commitizen-logo-color.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/logo/commitizen-logo-mono.svg b/logo/commitizen-logo-mono.svg new file mode 100644 index 00000000..66359fe7 --- /dev/null +++ b/logo/commitizen-logo-mono.svg @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/logo/generate.sh b/logo/generate.sh new file mode 100644 index 00000000..a9b2c051 --- /dev/null +++ b/logo/generate.sh @@ -0,0 +1,58 @@ +#!/bin/bash +set -o nounset +set -o errexit + +##################################################### +# Script to create PNG files from SVG source files. # +# Dependencies: cairosvg (https://cairosvg.org/) # +# # +# Rationale: Generating from SVG instead of storing # +# image files decreases size of repo and avoids # +# security vulnerabilites associated with binary # +# image files. # +##################################################### + +convert () { + COLOR=$1 + # echo "converting file $COLOR..." + FILE=logo/commitizen-logo-${COLOR}.svg + if [ ! -f ${FILE} ]; then + # echo "file $FILE missing!" + exit 1 + fi + # echo "conversion in progress..." + for SIZE in 16 48 96 256 512 1024; do + cairosvg ${FILE} -f png -W ${SIZE} -H ${SIZE} -d 300 -o logo/commitizen_logo_${COLOR}_${SIZE}x${SIZE}.png + done + # echo "done" + return 0 +} + +if [[ $(which cairosvg) == "" ]]; then + # We're not going to mess with installation on OSX or Windows in our build pipelines. + if [[ "$OSTYPE" == "darwin"* ]]; then + echo "cairosvg not found in PATH. Please see https://cairosvg.org/documentation/#installation" + exit 0 + elif [[ "$OSTYPE" == "msys"* ]]; then + echo "cairosvg not found in PATH. Please see https://cairosvg.org/documentation/#installation" + exit 0 + fi + pip3 install cairosvg +fi + +for COLOR in black blue white color; do + FILE=logo/commitizen-logo-${COLOR}.svg + if [ ! -f ${FILE} ]; then + # echo "generating file $FILE..." + sed 's|fill=\".*\"|fill=\"'${COLOR}'\"|g' ${FILE} + convert ${COLOR} + # echo "removing generated file $FILE..." + rm $FILE + # echo "success!" + else + # echo "file found: $FILE" + convert ${COLOR} + fi +done + +exit 0 \ No newline at end of file