Fix source watcher configuration

This commit is contained in:
Rene Klacan 2016-10-27 15:10:28 +02:00
parent 7c968b9572
commit 8b4e2d043c
4 changed files with 44 additions and 21 deletions

View file

@ -75,9 +75,10 @@ module Middleman
@ignored = options.fetch(:ignored, proc { false })
@only = Array(options.fetch(:only, []))
@disable_watcher = app.build? || @parent.options.fetch(:disable_watcher, false)
@force_polling = @parent.options.fetch(:force_polling, false)
@latency = @parent.options.fetch(:latency, nil)
@disable_watcher = app.build?
@force_polling = false
@latency = nil
@wait_for_delay = nil
@listener = nil
@ -95,13 +96,18 @@ module Middleman
def update_path(directory)
@directory = Pathname(File.expand_path(directory, app.root))
stop_listener! if @listener
without_listener_running do
update([], @files.values.map { |source_file| source_file[:full_path] })
end
end
update([], @files.values.map { |source_file| source_file[:full_path] })
poll_once!
listen! unless @disable_watcher
def update_config(options={})
without_listener_running do
@disable_watcher = options.fetch(:disable_watcher, false)
@force_polling = options.fetch(:force_polling, false)
@latency = options.fetch(:latency, nil)
@wait_for_delay = options.fetch(:wait_for_delay, nil)
end
end
# Stop watching.
@ -160,10 +166,10 @@ module Middleman
config = {
force_polling: @force_polling,
wait_for_delay: 0.5
}
config[:latency] = @latency.to_i if @latency
config[:wait_for_delay] = @wait_for_delay.try(:to_f) || 0.5
config[:latency] = @latency.to_f if @latency
@listener = ::Listen.to(@directory.to_s, config, &method(:on_listener_change))
@ -343,5 +349,20 @@ module Middleman
@only.any? { |reg| file[:relative_path].to_s =~ reg }
end
end
private
def without_listener_running
listener_running = @listener && @listener.processing?
stop_listener! if listener_running
yield
if listener_running
poll_once!
listen!
end
end
end
end