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