Merge pull request #1589 from dchest/better-watch
Replace directory_watcher with listen.
This commit is contained in:
commit
2287eed0c6
|
@ -25,7 +25,7 @@ Gem::Specification.new do |s|
|
|||
|
||||
s.add_runtime_dependency('liquid', "~> 2.5.2")
|
||||
s.add_runtime_dependency('classifier', "~> 1.3")
|
||||
s.add_runtime_dependency('directory_watcher', "~> 1.4.1")
|
||||
s.add_runtime_dependency('listen', "~> 2.0")
|
||||
s.add_runtime_dependency('maruku', "~> 0.6.0")
|
||||
s.add_runtime_dependency('pygments.rb', "~> 0.5.0")
|
||||
s.add_runtime_dependency('commander', "~> 4.1.3")
|
||||
|
|
|
@ -31,27 +31,34 @@ module Jekyll
|
|||
#
|
||||
# Returns nothing.
|
||||
def self.watch(site, options)
|
||||
require 'directory_watcher'
|
||||
require 'listen'
|
||||
|
||||
source = options['source']
|
||||
destination = options['destination']
|
||||
|
||||
begin
|
||||
ignored = Regexp.new(Regexp.escape(Pathname.new(destination)
|
||||
.relative_path_from(Pathname.new(source))
|
||||
.to_path))
|
||||
rescue ArgumentError
|
||||
# Destination is outside the source, no need to ignore it.
|
||||
ignored = nil
|
||||
end
|
||||
|
||||
Jekyll.logger.info "Auto-regeneration:", "enabled"
|
||||
|
||||
dw = DirectoryWatcher.new(source, :glob => self.globs(source, destination), :pre_load => true)
|
||||
dw.interval = 1
|
||||
|
||||
dw.add_observer do |*args|
|
||||
listener = Listen.to(source, ignore: ignored) do |modified, added, removed|
|
||||
t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
print Jekyll.logger.formatted_topic("Regenerating:") + "#{args.size} files at #{t} "
|
||||
n = modified.length + added.length + removed.length
|
||||
print Jekyll.logger.formatted_topic("Regenerating:") + "#{n} files at #{t} "
|
||||
self.process_site(site)
|
||||
puts "...done."
|
||||
end
|
||||
|
||||
dw.start
|
||||
listener.start
|
||||
|
||||
unless options['serving']
|
||||
trap("INT") do
|
||||
listener.stop
|
||||
puts " Halting auto-regeneration."
|
||||
exit 0
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue