Class: Bridgetown::Routines::FrontendWatcher

Inherits:
Object
  • Object
show all
Defined in:
bridgetown-core/lib/bridgetown-core/routines/frontend_watcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(site:) ⇒ FrontendWatcher

Returns a new instance of FrontendWatcher.



6
7
8
# File 'bridgetown-core/lib/bridgetown-core/routines/frontend_watcher.rb', line 6

def initialize(site:)
  @site = site
end

Instance Method Details

#execute(instance) ⇒ Object

rubocop:disable Metrics/AbcSize



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'bridgetown-core/lib/bridgetown-core/routines/frontend_watcher.rb', line 10

def execute(instance) # rubocop:disable Metrics/AbcSize
  return unless watch_frontend?

  if Bridgetown::Utils.frontend_bundler_type(@site.config[:root_dir]) == :esbuild
    Bridgetown::Utils.update_esbuild_autogenerated_config(@site.config)
  end

  require "rake"
  Rake.with_application do |rake|
    begin
      rake.raw_load_rakefile
    rescue StandardError => e
      unless e.message.include?("No Rakefile found")
        Bridgetown.logger.error "Error Running Rake:", "#{e.message} (#{e.class})"
        e.backtrace[0..1].each { |backtrace_line| Bridgetown.logger.info backtrace_line }
      end
    end

    instance.ready!
    rake["frontend:dev"].invoke(true) if rake.tasks.any? { _1.name == "frontend:dev" }
  end
end

#keyObject



34
# File 'bridgetown-core/lib/bridgetown-core/routines/frontend_watcher.rb', line 34

def key   = :frontend_watcher

#nameObject



33
# File 'bridgetown-core/lib/bridgetown-core/routines/frontend_watcher.rb', line 33

def name  = "Bridgetown Frontend Watcher"

#tagObject



35
# File 'bridgetown-core/lib/bridgetown-core/routines/frontend_watcher.rb', line 35

def tag   = { value: "Frontend", color: :blue }