Class: Zui::Distribution

Inherits:
Object
  • Object
show all
Defined in:
lib/zui/distribution.rb

Constant Summary collapse

RUNTIME_MODES =
%i[lite full].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client: nil, platform: Platform.current, framework_root: FRAMEWORK_ROOT, ruby: RbConfig.ruby, tree_shake: true, release_config: nil, runtime_mode: :lite, runtime_builder: nil) ⇒ Distribution

Returns a new instance of Distribution.



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

def initialize(client: nil, platform: Platform.current, framework_root: FRAMEWORK_ROOT,
               ruby: RbConfig.ruby, tree_shake: true, release_config: nil, runtime_mode: :lite,
               runtime_builder: nil)
  @platform = platform.assert_supported!
  @client = client || Client.new(platform: @platform)
  @framework_root = framework_root
  @ruby = File.expand_path(ruby)
  @tree_shake = tree_shake == true
  @runtime_mode = runtime_mode.to_sym
  unless RUNTIME_MODES.include?(@runtime_mode)
    raise ArgumentError, "unsupported application runtime: #{runtime_mode}"
  end
  @tree_shake_report = nil
  @release_config = release_config
  @runtime_builder = runtime_builder
  @application_runtime = nil
end

Instance Attribute Details

#platformObject (readonly)

Returns the value of attribute platform.



11
12
13
# File 'lib/zui/distribution.rb', line 11

def platform
  @platform
end

#runtime_modeObject (readonly)

Returns the value of attribute runtime_mode.



11
12
13
# File 'lib/zui/distribution.rb', line 11

def runtime_mode
  @runtime_mode
end

#tree_shake_reportObject (readonly)

Returns the value of attribute tree_shake_report.



11
12
13
# File 'lib/zui/distribution.rb', line 11

def tree_shake_report
  @tree_shake_report
end

Instance Method Details

#bundle(source, name: nil, destination: nil) ⇒ Object



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
# File 'lib/zui/distribution.rb', line 31

def bundle(source, name: nil, destination: nil)
  created = false
  project = File.expand_path(source)
  @project = project
  raise ArgumentError, "project directory not found: #{project}" unless File.directory?(project)
  raise ArgumentError, "main.rb not found: #{project}" unless File.file?(File.join(project, "main.rb"))
  unless @client.configured?
    raise ArgumentError, "Zui is not configured for #{platform.id}; run `zui doctor --fix` before bundling"
  end
  app_name = name || titleize(File.basename(project))
  destination ||= default_destination(project, app_name)
  destination = File.expand_path(destination)
  raise ArgumentError, "bundle destination already exists: #{destination}" if File.exist?(destination)
  created = true

  case platform.os
  when :linux then bundle_linux(project, destination, app_name)
  when :macos then bundle_macos(project, destination, app_name)
  when :windows then bundle_windows(project, destination, app_name)
  end
  destination
rescue StandardError
  FileUtils.remove_entry(destination) if created && destination && File.exist?(destination)
  raise
end