Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: a113949637
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 89 lines (67 sloc) 2.381 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#! /bin/bash

# Facebook all.js deminifyier and updater script.
# Tracks changes to all.js & all.css with some help
#
# By Nathan Friedly - http://nfriedly.com
#
# This script is released under an MIT License. Accompanying files
# may have different licenses.


###
# Function that downloads the latest all.js/css file and compares it to the old one.
#
# If only the timestamp has changed, it restores the old file
#
# @param {string} fileType - "js" or "css"
# @return {int} changed - 0 if nothing but the timestamp changed, 1 if other lines have changed
###
getChanges(){
# make a backup copy to diff against the latest all.js/css.
mv all.$1 all_old.$1

# download the latest facebook all.js/css
/usr/bin/wget -q -O all.$1 https://connect.facebook.net/en_US/all.$1

# compare the latest with the backup to see if anything besides the
# timestamp comment at the top changed
local changes=$(/usr/bin/diff --brief --ignore-matching-lines=\/\*.*\*\/ all.$1 all_old.$1)

# an empty string is falsy, a string with text is truthy
if [[ $changes ]]; then
# something else has changed
# get rid of the old file
rm all_old.$1
else
# no changes, or only the timestamp changed
# put back the old file
mv all_old.$1 all.$1
fi

# this is the "return" value - some text if there were changes or "" otherwise
echo $changes
}

# change to the directory where this script is located
cd `dirname $0`

# check for js/css changes
JS_CHANGES=$(getChanges "js")

CSS_CHANGES=$(getChanges "css")

# if anything has changed besides the timestamp in the JS
if [[ $JS_CHANGES ]]; then

# deminify the script
/usr/bin/python lib/jsbeautifier.py -o all_deminified.js all.js

# add it to the staging area
/usr/bin/git add *.js
fi

# if anything has changed besides the timestamp in the CSS
if [[ $CSS_CHANGES ]]; then

# deminify the file
# this requires php5-cli
/usr/bin/php csstidy_wrapper.php all.css all_deminified.css

# add it to the staging area
/usr/bin/git add *.css
fi

# if anything changed in either file, commit and push to github
if [[ $JS_CHANGES || $CSS_CHANGES ]]; then

echo "Sending changes to github"

# commit with yesterday's date since this is typically run
# shortly after midnight
/usr/bin/git commit -m "FB changes from `date --date=yesterday +'%A, %B %-d, %Y'`"
/usr/bin/git push -q origin master

else
echo "No changes"
fi

Something went wrong with that request. Please try again.