Created
July 29, 2013 09:34
-
-
Save dominik-hadl/6103227 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# 7zJSON.sh | |
# @author Dominik Hadl | |
# @dependencies This script requires that you have p7zip package installed, prefferably through Homebrew. | |
# | |
# @description This script will automatically find all .json files in your $BUILT_PRODUCTS_DIR and will compress them to the LZMA (7z) format. | |
# In the process it will also delete the original .json files - but only in the build folder. | |
# | |
# @usage | |
# 1. Create a new build phase (Run script) in your target in Xcode | |
# 2. Copy the script below | |
# 3. Add a preprocessor macro to both Debug and Release called "LZMA_7ZIP_SUPPORT" to enable | |
#--------------------------------------------------------------------------------------------------------- | |
# Get preprocessor macros | |
MACROS="${GCC_PREPROCESSOR_DEFINITIONS}"; | |
# Check if LZMA_7ZIP_SUPPORT is set | |
if [[ $MACROS == *LZMA_7ZIP_SUPPORT* ]]; then | |
echo "Compressing JSON files into 7z." | |
# Path to P7ZIP (modify if needed) | |
P7ZIP="/usr/local/bin/7z" | |
# Check if command exists | |
command -v ${P7ZIP} > /dev/null || exit 0 | |
# Disable spacing by space for a while | |
oIFS=$IFS | |
IFS=$'\n' | |
# Find the .jsons, compress them and delete the .json files | |
find "$BUILT_PRODUCTS_DIR" -name '*.json' | while read -r i; do | |
JSON_NO_EXT=${i%\.*n} | |
${P7ZIP} a "${JSON_NO_EXT}.7z" "$i" | |
rm -rf "$i" | |
done | |
# Set back the spacing | |
IFS=$oIFS | |
else | |
echo "7z compression is disabled. Please set the preprocessor macro to enable." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment