Skip to content

Instantly share code, notes, and snippets.

@deecewan
Last active April 27, 2018 01:31
Show Gist options
  • Save deecewan/481aa7f0bbb308353c4fde1bdafbffc6 to your computer and use it in GitHub Desktop.
Save deecewan/481aa7f0bbb308353c4fde1bdafbffc6 to your computer and use it in GitHub Desktop.
Create icons for different flavours in a react native project. Uses bash because macOS comes with it
#!/usr/bin/env bash
typeset -a FLAVORS
####
# This creates icons in all the necessary sizes for a react native project
# To use, simply set the variables after this block
# Note, this expects your standard icon to be named `icon.png`, and
# all flavor icons to be named `icon_<flavor>.png`. For example,
# `icon_dogfood.png` and `icon_nightly.png`
#
# You'll also need to `yarn add -D yo generator-rn-toolbox` first.
#
# Instructions:
# - Put this script in your project somewhere
# - Make it executable (chmod +x /path/to/generate-icons.sh
# - Update the variables below
# - run `/path/to/generate-icons.sh`
# - If you get a conflict on your first run, choose 'y' to overwrite the old icons
####
PROJECT_NAME="my-cool-project" # the name of your project (take a look at app.json if you aren't sure)
ICON_LOCATION="assets/icons" # where do your raw, full-size icons live, relative to your project root (no trailing slash)
FLAVORS=("dogfood" "nightly") # enter all your flavors in between the parentheses, separated by a space.
# you'll need to have imagemagick installed so that rn-toolbox can resize
if ! which convert > /dev/null; then
echo "You must have imagemagick installed"
echo "Try \`brew install imagemagick\`"
exit 1
fi
function _run_command() {
local ICON_NAME="icon"
local ANDROID_LOCATION=""
local IOS_ASSET_NAME=""
if [ "$1" != "" ]; then
ICON_NAME="icon_$1"
ANDROID_LOCATION="--androidSrcDirectory $1"
local ios_sub=$( echo "${1:0:1}" | tr '[:lower:]' '[:upper:]' )
ios_sub="$ios_sub${1:1}"
IOS_ASSET_NAME="--iosAssetName AppIcon.$ios_sub"
fi
yarn yo rn-toolbox:assets \
--projectName "$PROJECT_NAME" \
--icon "$ICON_LOCATION/$ICON_NAME".png \
$ANDROID_LOCATION $IOS_ASSET_NAME
}
echo "Generating icons for release"
_run_command
for flavor in "${FLAVORS[@]}"; do
echo "Generating icons for $flavor"
_run_command $flavor
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment