Skip to content

Commit c84b330

Browse files
committed
fix guard for non-symlinked plugins
also remove the need for Guardfile within plugins (and stop including them) note that guard still can't detect changes to files in symlinked plugins on the mac (due to fsevent), though you can hit enter to recompile everything test plan: 1. clone a plugin into vendor/plugins 2. start up guard 3. edit a coffee file in the plugin 4. guard should detect it and compile it in the right place 5. edit a coffee spec file in the plugin 6. guard should detect it and compile it in the right place 7. edit a handlebars file in the plugin 8. guard should detect it and compile it in the right place 9. hit enter 10. guard should compile all coffee/handlebars files in the right place Change-Id: I1e7c12f1368af66dee024e258899412526bb3fd2 Reviewed-on: https://gerrit.instructure.com/20219 Tested-by: Jenkins <[email protected]> Reviewed-by: Ryan Florence <[email protected]> Product-Review: Jon Jensen <[email protected]> QA-Review: Jon Jensen <[email protected]>
1 parent 63bde15 commit c84b330

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ group :test do
121121
end
122122

123123
group :development do
124-
gem 'guard', '1.6.0'
124+
gem 'guard', '1.8.0'
125125
gem 'rb-inotify', '~>0.9.0', :require => false
126126
gem 'rb-fsevent', :require => false
127127
gem 'rb-fchange', :require => false

Guardfile

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
$LOAD_PATH << File.dirname(__FILE__)
22

3+
ignore! Listen::DirectoryRecord::DEFAULT_IGNORED_DIRECTORIES - ['vendor'] + [%r{vendor/(?!plugins)}]
4+
35
guard 'coffeescript', :input => 'app/coffeescripts', :output => 'public/javascripts/compiled'
46
guard 'coffeescript', :input => 'spec/coffeescripts', :output => 'spec/javascripts'
7+
guard 'coffeescript', :input => 'spec_canvas/coffeescripts', :output => 'spec_canvas/javascripts'
58
guard 'jst', :input => 'app/views/jst', :output => 'public/javascripts/jst'
69
guard :styleguide
710
guard :js_extensions
811

9-
Dir[File.join(File.dirname(__FILE__),'vendor/plugins/*/Guardfile')].each do |g|
10-
eval(File.read(g))
11-
end
12-

guard/coffeescript.rb

+18-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ class << self
4747

4848
def run(files, watchers, options = { })
4949
notify_start(files, options)
50-
changed_files, errors = compile_files(files, watchers, options)
50+
changed_files, errors = partition_by_plugin(files) do |prefix, plugin_files|
51+
compile_files(plugin_files, watchers, options.merge(:output => "#{prefix}#{options[:output]}"))
52+
end
5153
notify_result(changed_files, errors, options)
5254

5355
[changed_files, errors.empty?]
@@ -58,6 +60,20 @@ def run(files, watchers, options = { })
5860

5961
private
6062

63+
def partition_by_plugin(files, &block)
64+
groupings = files.inject({}) { |hash, file|
65+
prefix = file =~ %r{\Avendor/plugins/.*?/} ? $& : ''
66+
hash[prefix] ||= []
67+
hash[prefix] << file
68+
hash
69+
}
70+
groupings.map(&block).inject([[], []]) { |ary, ret|
71+
ary[0].concat ret[0]
72+
ary[1].concat ret[1]
73+
ary
74+
}
75+
end
76+
6177
def notify_start(files, options)
6278
message = options[:message] || (options[:noop] ? 'Verify ' : 'Compile ') + files.join(', ')
6379
Formatter.info(message, :reset => true)
@@ -167,7 +183,7 @@ def initialize(watchers = [], options = {})
167183

168184
if options[:input]
169185
defaults.merge!({ :output => options[:input] })
170-
watchers << ::Guard::Watcher.new(%r{^#{ options.delete(:input) }/(.+\.coffee)$})
186+
watchers << ::Guard::Watcher.new(%r{\A(?:vendor/plugins/.*?/)?#{ Regexp.escape(options.delete(:input)) }/(.+\.coffee)\z})
171187
end
172188

173189
super(watchers, defaults.merge(options))

guard/jst.rb

+7-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def initialize(watchers = [], options = {})
2727

2828
if options[:input]
2929
defaults.merge!({ :output => options[:input] })
30-
watchers << ::Guard::Watcher.new(%r{^#{ options[:input] }/(.+\.handlebars)$})
30+
watchers << ::Guard::Watcher.new(%r{\A(?:vendor/plugins/.*?/)?#{ Regexp.escape(options[:input]) }/(.+\.handlebars)\z})
3131
end
3232

3333
super(watchers, defaults.merge(options))
@@ -49,10 +49,14 @@ def start
4949
#
5050
# Compiles templates from app/views/jst to public/javascripts/jst
5151
def run_on_change(paths)
52-
Parallel.each(paths, :in_threads => Parallel.processor_count) do |path|
52+
paths = paths.map{ |path|
53+
prefix = path =~ %r{\Avendor/plugins/.*?/} ? $& : ''
54+
[prefix, path]
55+
}
56+
Parallel.each(paths, :in_threads => Parallel.processor_count) do |prefix, path|
5357
begin
5458
UI.info "Compiling: #{path}"
55-
Handlebars.compile_file path, 'app/views/jst', @options[:output]
59+
Handlebars.compile_file path, "#{prefix}app/views/jst", "#{prefix}#{@options[:output]}"
5660
rescue Exception => e
5761
::Guard::Notifier.notify(e.to_s, :title => path.sub('app/views/jst/', ''), :image => :failed)
5862
end

0 commit comments

Comments
 (0)