Class: Klenod::Build::CLI::Build

Inherits:
Samovar::Command
  • Object
show all
Defined in:
lib/klenod/build/cli/application.rb

Instance Method Summary collapse

Instance Method Details

#callObject

Raises:

  • (Samovar::InvalidInputError)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/klenod/build/cli/application.rb', line 25

def call
  config_path = Klenod::Build::ConfigLoader.find
  raise Samovar::InvalidInputError.new(self, ["Could not find klenod.config.rb"]) unless config_path

  config = nil
  Dir.chdir(File.dirname(config_path)) do
    config = Klenod::Build::ConfigLoader.load(config_path)
  end
  entrypoints = config.entrypoints
  raise Samovar::MissingValueError.new(self, :entry) if entrypoints.empty?

  output = config.output_path
  assets_dir = config.assets_path

  bundle = nil
  Dir.chdir(config.base_dir) do
    context = config.context(mode: :build)
    bundle =
      if @options[:executable]
        context.build_executable(entrypoints: entrypoints, output: output, assets_dir: assets_dir)
      else
        context.build(entrypoints: entrypoints, output: output, assets_dir: assets_dir)
      end
  end

  self.output.puts "Built #{build_kind} #{output}"
  self.output.puts "Source root: #{bundle.source_root}"
  self.output.puts "Entrypoints: #{bundle.entrypoints.keys.join(", ")}"
  self.output.puts "Assets: #{bundle.assets.length}"
  self.output.puts "Assets directory: #{assets_dir}" if assets_dir

  bundle
end