Class: ShopifyCLI::Theme::DevServer::Hooks::FileChangeHook

Inherits:
Object
  • Object
show all
Includes:
IgnoreHelper
Defined in:
lib/shopify_cli/theme/dev_server/hooks/file_change_hook.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from IgnoreHelper

#ignore_file?, #ignore_operation?, #ignore_path?

Constructor Details

#initialize(ctx, theme:, include_filter: nil, ignore_filter: nil) ⇒ FileChangeHook

Returns a new instance of FileChangeHook.



15
16
17
18
19
20
# File 'lib/shopify_cli/theme/dev_server/hooks/file_change_hook.rb', line 15

def initialize(ctx, theme:, include_filter: nil, ignore_filter: nil)
  @ctx = ctx
  @theme = theme
  @include_filter = include_filter
  @ignore_filter = ignore_filter
end

Instance Attribute Details

#ignore_filterObject (readonly)

Returns the value of attribute ignore_filter.



13
14
15
# File 'lib/shopify_cli/theme/dev_server/hooks/file_change_hook.rb', line 13

def ignore_filter
  @ignore_filter
end

#include_filterObject (readonly)

Returns the value of attribute include_filter.



13
14
15
# File 'lib/shopify_cli/theme/dev_server/hooks/file_change_hook.rb', line 13

def include_filter
  @include_filter
end

Instance Method Details

#call(modified, added, removed, streams: nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/shopify_cli/theme/dev_server/hooks/file_change_hook.rb', line 22

def call(modified, added, removed, streams: nil)
  @streams = streams
  files = (modified + added)
    .map { |f| @theme[f] }
    .reject { |f| ignore_file?(f) }
  files -= liquid_css_files = files.select(&:liquid_css?)
  deleted_files = removed
    .map { |f| @theme[f] }
    .reject { |f| ignore_file?(f) }

  remote_delete(deleted_files) unless deleted_files.empty?
  reload_page(removed) unless deleted_files.empty?

  hot_reload(files) unless files.empty?
  remote_reload(liquid_css_files)
end