Last active
December 19, 2015 20:08
-
-
Save dominik-hadl/6011179 to your computer and use it in GitHub Desktop.
Automatically minifies all JSON files after building (release or debug).
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
#!/usr/bin/python | |
#------------------------- | |
# Import the dependencies | |
#------------------------- | |
import json, sys | |
#------------------------- | |
#------------------------------------- | |
# Get the file names from the argument | |
#------------------------------------- | |
files = sys.argv[1:] | |
#------------------------------------- | |
#------------------------------------- | |
# Repeat for all the files | |
#------------------------------------- | |
for jsonFile in files: | |
#------------------------------------- | |
#------------------------- | |
# Open the file | |
#------------------------- | |
with open(jsonFile) as f: | |
data = json.load(f) | |
#------------------------- | |
#------------------------- | |
# Compact JSON encoding | |
#------------------------- | |
compressed = json.dumps(data, separators=( ',', ':' )) | |
#------------------------- | |
#------------------------------------------- | |
# Replace the contents with the compact JSON | |
#------------------------------------------- | |
with open(jsonFile, 'w') as f: | |
f.write(compressed) | |
#------------------------------------------- | |
#------------------------------------- |
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
# xcode-auto-json-minify.sh | |
# Author: Dominik Hadl (@dominikhadl) | |
# @desc Automatically minifies all JSON files after building (release or debug). | |
# @usage | |
# 1. Add 'JSONPrettyToUgly.py' script to your project (make sure 'copy files if needed blabla...' checkbox is selected) and uncheck your target. | |
# 2. Go to your project (blue icon in the top of file navigator), select your target, then to "Build Phases" and "Add Build Phase" with "Add Run Script". | |
# 3. Move the script after the "Copy Bundle Resources" phase and paste in this script. | |
# 4. Enjoy minifed JSON files and faster loading times on the device or simulator! :) | |
PYTHONSCRIPT=$(find "${SRCROOT}" -name "JSONPrettyToUgly.py"); | |
find "${BUILT_PRODUCTS_DIR}" -name "*.json" -exec "$PYTHONSCRIPT" {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment