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.



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

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.



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

def build(*args)
  last_build = (ssr: args.include?("--ssr"))

  if args.delete("--force") || last_build.stale? || config.manifest_paths.empty?
    stdout, stderr, status = build_with_vite(*args)
    log_build_result(stdout, stderr, status)
    (last_build, errors: stderr, success: status.success?)
    status.success?
  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_metadata(ssr: false) ⇒ Object

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



31
32
33
# File 'lib/vite_ruby/builder.rb', line 31

def (ssr: false)
  ViteRuby::Build.from_previous(last_build_path(ssr: ssr), watched_files_digest)
end