Created
November 22, 2011 02:39
-
-
Save stakes/1384731 to your computer and use it in GitHub Desktop.
Jamm Them Assets
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/env ruby | |
require 'jammit' | |
print "JAMMIT: Looking for changes to tracked assets... " | |
# take a look at the status before compression | |
status_before = %x[git status --porcelain --untracked-files=no] | |
# package changed assets | |
Jammit.package! | |
# now take a look at the status after compressing assets | |
status_after = %x[git status --porcelain --untracked-files=no] | |
# compare the status before and after compressing | |
jammit_files = (status_after.split("\n") - status_before.split("\n")).map { |f| f.split[1] } | |
# if there's no difference, there's nothing to add to the commit | |
# but if there is a difference, Jammit has compressed something | |
if !jammit_files.empty? | |
# give feedback as to what just happened | |
puts "\nPackaged #{jammit_files.count} files.\nAdding packaged files to the commit:" | |
jammit_files.each do |file| | |
puts file | |
end | |
# and then add the newly-changed files to the commit | |
`git add #{jammit_files.join(' ')}` | |
else | |
puts "and there aren't any." | |
end | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment