标签:
I’ve just returned from NSConference #5, there were many good talks there, but my favourite one was the one about Flipboard development tools/setup by Evan Doll.
Especially how they add version information on top of the icons.Unfortunately they didn’t share it with us.
So I wrote my own.
I’ve decided that 3 parts of information should be enough:
We can extract version number straight from our application .plist file by using PlistBuddy tool:
version=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${INFOPLIST_FILE}"`
PS. You could extract any plist entry with this tool, just change CFBundleVersion to different key (show raw keys in Xcode)
git command line tool offers rev-parse command which let’s you both of those variables:
commit=`git rev-parse --short HEAD`
branch=`git rev-parse --abbrev-ref HEAD`
ImageMagic is my go-to tool for playing with images from command line, it offers crazy amount of functions.
Make sure to install ImageMagick and ghostscript (fonts) first, you can use brew to simplify process:
brew install imagemagick
brew install ghostscript
We can use convert function, by specifing caption parameter imagemagick will layout our text on top of image, we also setup alignment to bottom and default height.
convert -background ‘#0008‘ -fill white -gravity center -size ${width}x40 \
caption:"${version} ${branch} ${commit}" ${base_file} +swap -gravity south -composite "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/${target_file}"
There are few steps we need to take in order to set this up as part of Xcode build:
commit=`git rev-parse --short HEAD`
branch=`git rev-parse --abbrev-ref HEAD`
version=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${INFOPLIST_FILE}"`
function processIcon() {
export PATH=$PATH:/usr/local/bin
base_file=$1
base_path=`find ${SRCROOT} -name $base_file`
if [[ ! -f ${base_path} || -z ${base_path} ]]; then
return;
fi
target_file=`echo $base_file | sed "s/_base//"`
target_path="${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/${target_file}"
if [ $CONFIGURATION = "Release" ]; then
cp ${base_file} $target_path
return
fi
width=`identify -format %w ${base_path}`
convert -background ‘#0008‘ -fill white -gravity center -size ${width}x40\
caption:"${version} ${branch} ${commit}" ${base_path} +swap -gravity south -composite ${target_path}
}
processIcon "Icon_base.png"
processIcon "Icon@2x_base.png"
processIcon "Icon-72_base.png"
processIcon "Icon-72@2x_base.png"
Few things about final script:
Now run your project and you should see this:
标签:
原文地址:http://blog.csdn.net/jiang314/article/details/51362966