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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/bonethug/watcher.rb', line 21
def self.watch(type = 'coffee_sass', target = '.', watch_only = nil)
target = File.expand_path target
puts "Parsing Config..."
unless conf = Conf.new.add(target + '/config/cnf.yml')
puts "Couldn't find project configuration"
return
end
project_type = conf.get('deploy.project_type')
if ['rails','rails3'].include? project_type
puts "Rails doesn't require watching"
return
end
sass = []
if sasses = conf.get('watch.sass')
sasses.each do |index, watch|
sass.push(src: watch.get('src','Array'), dest: watch.get('dest'), filter: watch.get('filter'), type: :sass)
end
end
coffee = []
if coffees = conf.get('watch.coffee')
coffees.each do |index, watch|
coffee.push(src: watch.get('src','Array'), dest: watch.get('dest'), filter: watch.get('filter'), type: :coffee)
end
end
watches = coffee + sass
puts 'Generating Guardfile...'
guardfile_content = ''
watches.each do |watch|
case watch[:filter].class.name
when 'NilClass'
watch_val = ''
when 'String'
watch_val = "'#{watch[:filter]}'"
when 'Regexp'
watch_val = watch[:filter].inspect
else
raise "invalid filter type: " + watch[:filter].class.name
end
filter = watch[:filter] ? "watch #{watch_val}" : ""
case type
when 'sprockets'
guardfile_content += "
guard 'sprockets', :minify => true, :destination => '#{watch[:dest]}', :asset_paths => #{watch[:src].to_s} do
#{filter}
end
"
when 'sass_coffee', 'coffee_sass'
if watch[:type] == :coffee
guardfile_content += "
guard :coffeescript, :minify => true, :output => '#{watch[:dest]}', :input => #{watch[:src].to_s} do
#{filter}
end
"
elsif watch[:type] == :sass
guardfile_content += "
guard :sass, :style => :compressed, :debug_info => true, :output => '#{watch[:dest]}', :input => #{watch[:src].to_s} do
#{filter}
end
"
end
end
end
guardfile = target + '/.bonethug/Guardfile'
FileUtils.rm_rf guardfile
File.open(guardfile,'w') do |file|
file.puts guardfile_content
end
puts 'Starting Watch Daemon...'
exec 'bundle exec guard --guardfile "' + target + '/.bonethug/Guardfile"'
end
|