require 'pathname' module Overcommit::Hook::PreCommit # Ensure the livescript source files are compiled. # Also make sure they're included in the commit. class EnsureLivescriptCompiled < Base def compiled_path ls ls.sub('livescript/', 'public/js/').sub(/\.ls$/, '.js') end def relative path Pathname.new(path).relative_path_from Pathname.getwd end def check_file lsfile compiled = compiled_path lsfile return "#{relative compiled}: older than #{relative lsfile}. $ ./compile_ls &" if File.stat(lsfile) > File.stat(compiled) return "#{relative lsfile}: compiled file not added. $ git add #{relative compiled}" unless modified_files.include? compiled end def run errs = applicable_files.map(&method(:check_file)).compact return :bad, errs.join('\n') unless errs.empty? :good end end end