Add file watcher :only option
This commit is contained in:
parent
c94e5d0f4d
commit
26c6f453f3
7 changed files with 20 additions and 9 deletions
|
@ -59,7 +59,7 @@ module Middleman::Cli
|
|||
glob: options['glob'],
|
||||
clean: options['clean'],
|
||||
parallel: options['parallel'])
|
||||
|
||||
builder.thor = self
|
||||
builder.on_build_event(&method(:on_event))
|
||||
|
||||
if builder.run!
|
||||
|
|
|
@ -12,6 +12,9 @@ module Middleman
|
|||
# Make app & events available to `after_build` callbacks.
|
||||
attr_reader :app, :events
|
||||
|
||||
# Reference to the Thor class.
|
||||
attr_accessor :thor
|
||||
|
||||
# Logger comes from App.
|
||||
def_delegator :@app, :logger
|
||||
|
||||
|
@ -130,7 +133,8 @@ module Middleman
|
|||
def write_tempfile(output_file, contents)
|
||||
file = Tempfile.new([
|
||||
File.basename(output_file),
|
||||
File.extname(output_file)])
|
||||
File.extname(output_file)
|
||||
])
|
||||
file.binmode
|
||||
file.write(contents)
|
||||
file.close
|
||||
|
|
|
@ -29,7 +29,7 @@ module Middleman
|
|||
# Tell the file watcher to observe the :data_dir
|
||||
@watcher = app.files.watch :data,
|
||||
path: File.join(app.root, dir),
|
||||
ignore: proc { |f| !DATA_FILE_MATCHER.match(f[:relative_path]) }
|
||||
only: DATA_FILE_MATCHER
|
||||
|
||||
# Setup data files before anything else so they are available when
|
||||
# parsing config.rb
|
||||
|
|
|
@ -19,7 +19,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|||
# Tell the file watcher to observe the :data_dir
|
||||
app.files.watch :locales,
|
||||
path: File.join(app.root, locales_file_path),
|
||||
ignore: proc { |f| !(/.*(rb|yml|yaml)$/.match(f[:relative_path])) }
|
||||
only: /.*(rb|yml|yaml)$/
|
||||
|
||||
# Setup data files before anything else so they are available when
|
||||
# parsing config.rb
|
||||
|
|
|
@ -283,6 +283,8 @@ module Middleman
|
|||
@app.after_build do |builder|
|
||||
if ext.method(:after_build).arity == 1
|
||||
ext.after_build(builder)
|
||||
elsif ext.method(:after_build).arity == 2
|
||||
ext.after_build(builder, builder.thor)
|
||||
else
|
||||
ext.after_build
|
||||
end
|
||||
|
|
|
@ -114,9 +114,7 @@ module Middleman
|
|||
# config.rb
|
||||
files.watch :reload,
|
||||
path: root,
|
||||
ignored: proc { |file|
|
||||
match_against.none? { |m| file[:relative_path].to_s.match(m) }
|
||||
}
|
||||
only: match_against
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ module Middleman
|
|||
|
||||
@validator = options.fetch(:validator, proc { true })
|
||||
@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)
|
||||
|
@ -132,6 +133,8 @@ module Middleman
|
|||
|
||||
@listener = ::Listen.to(@directory.to_s, config, &method(:on_listener_change))
|
||||
@listener.start
|
||||
|
||||
@listener.only(@only) unless @only.empty?
|
||||
end
|
||||
|
||||
# Stop the listener.
|
||||
|
@ -259,9 +262,13 @@ module Middleman
|
|||
# @return [Boolean]
|
||||
Contract IsA['Middleman::SourceFile'] => Bool
|
||||
def valid?(file)
|
||||
@validator.call(file) &&
|
||||
!globally_ignored?(file) &&
|
||||
globally_valid = @validator.call(file) && !globally_ignored?(file)
|
||||
|
||||
globally_valid && if @only.empty?
|
||||
!@ignored.call(file)
|
||||
else
|
||||
@only.any? { |reg| reg.match(file[:relative_path].to_s) }
|
||||
end
|
||||
end
|
||||
|
||||
# Convert a path to a file resprentation.
|
||||
|
|
Loading…
Reference in a new issue