Created
May 15, 2011 11:22
-
-
Save ivanvanderbyl/973066 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
# !/usr/bin/env ruby | |
# | |
# A pre-commit hook to test if jammit needs to be run | |
# In case you don't like on the fly stuff | |
require 'rubygems' | |
require "bundler" | |
Bundler.setup | |
require 'jammit' | |
puts Jammit::DEFAULT_CONFIG_PATH | |
def check_assets(config) | |
Jammit.load_configuration(config) | |
[:javascripts, :stylesheets].each do |type| | |
Jammit.configuration[type].each do |key, globs| | |
if !check_group(type, key, globs) | |
$stderr.puts "run jammit" | |
exit 1 | |
end | |
end | |
end | |
end | |
def check_group(type, key, globs) | |
case type | |
when :js, :javascripts | |
ext = '.js' | |
when :css, :stylesheets | |
ext = '.css' | |
else | |
raise ArgumentError "Invalid type" | |
end | |
asset_path = File.join('public', Jammit.package_path, "#{key}#{ext}") | |
if !File.exists?(asset_path) | |
$stderr.puts "asset #{asset_path} missing" | |
return false | |
end | |
mtime = File.mtime(asset_path) | |
globs.each do |g| | |
Dir.glob(g) do |filename| | |
if File.mtime(filename) > mtime | |
$stderr.puts "#{filename} newer then #{asset_path}" | |
return false | |
end | |
end | |
end | |
true | |
end | |
check_assets(Jammit::DEFAULT_CONFIG_PATH) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment