Skip to content

Instantly share code, notes, and snippets.

@Lukasa
Created August 17, 2012 14:33
Show Gist options
  • Save Lukasa/3379184 to your computer and use it in GitHub Desktop.
Save Lukasa/3379184 to your computer and use it in GitHub Desktop.
Post-commit hook for use with Django's collectstatic.
#!/bin/bash
# This script should be placed in the .git/hooks directory and marked
# executable. It has the effect of minifying all of the files in the
# _static/css directory and placing them in the static/css directory, before
# pushing them to S3.
set -e
# Set some constants
INDIR="_static/css"
OUTDIR="static/css"
# Enumerate the files.
FILES=`ls $INDIR`
# Compress each one.
for f in $FILES
do
echo "Minifying $f..."
yuicompressor --type css -o "$OUTDIR/$f" "$INDIR/$f"
done
# Upload the newly compressed files.
echo "Connecting into the virtualenv"
source venv/bin/activate
echo "Uploading static files..."
python manage.py collectstatic --noinput
echo "Disconnecting from the virtualenv"
deactivate
echo "Done."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment