Class: ViteRuby::Builder

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vite_ruby/builder.rb

Overview

Public: Keeps track of watched files and triggers builds as needed.

Instance Method Summary collapse

Constructor Details

#initialize(vite_ruby) ⇒ Builder

Returns a new instance of Builder.



8
9
10
# File 'lib/vite_ruby/builder.rb', line 8

def initialize(vite_ruby)
  @vite_ruby = vite_ruby
end

Instance Method Details

#build(*args) ⇒ Object

Public: Checks if the watched files have changed since the last compilation, and triggers a Vite build if any files have changed.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vite_ruby/builder.rb', line 14

def build(*args)
  last_build = 
  if args.delete('--force') || last_build.stale?
    build_with_vite(*args).tap { |success| (success, last_build) }
  elsif last_build.success
    logger.debug "Skipping vite build. Watched files have not changed since the last build at #{ last_build.timestamp }"
    true
  else
    logger.error "Skipping vite build. Watched files have not changed since the build failed at #{ last_build.timestamp }"
    false
  end
end

#last_build_metadataObject

Internal: Reads the result of the last compilation from disk.



28
29
30
# File 'lib/vite_ruby/builder.rb', line 28

def 
  ViteRuby::Build.from_previous(last_build_attrs, watched_files_digest)
end