-
Notifications
You must be signed in to change notification settings - Fork 53
/
Guardfile
36 lines (30 loc) · 1.13 KB
/
Guardfile
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
require 'stitch-rb'
require 'uglifier'
require 'coffee-script'
guard 'coffeescript', :input => 'coffeescripts', :output => 'javascripts'
guard :compass do
watch(%r{^assets/stylesheets/(.*)\.s[ac]ss$})
end
guard :shell do
watch /^assets\/javascripts\/.+\.(js|coffee)/ do |change|
file = "javascripts/hslpicker.js"
env = 'production'
lib = ['underscore.js', 'backbone.js', 'dragdealer.js'].collect {|item| Dir.glob("assets/javascripts/lib/#{item}") }.flatten.uniq
modules = Dir.glob('assets/javascripts/modules/*.*')
fingerprint = Digest::MD5.hexdigest((lib|modules).map! { |path| "#{File.mtime(path).to_i}" }.join+env)
if File.exists?(file) and File.open(file) {|f| f.readline} =~ /#{fingerprint}/
false
else
js = Stitch::Package.new(:paths => 'assets/javascripts/modules', :dependencies => lib).compile
js = Uglifier.new.compile(js) if env == 'production'
js = "/* fingerprint: #{fingerprint} */\n" + js
begin
File.open(file, 'w') { |f| f.write js }
rescue => e
puts e.message, e.backtrace
exit(-1)
end
puts "Generated #{file}"
end
end
end