Class: Zui::DistPackager

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

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, environment: ENV, runtime_mode: :lite, runtime_builder: nil) ⇒ DistPackager

Returns a new instance of DistPackager.



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

def initialize(client: nil, platform: Platform.current, framework_root: FRAMEWORK_ROOT,
               ruby: RbConfig.ruby, tree_shake: true, environment: ENV, 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 Distribution::RUNTIME_MODES.include?(@runtime_mode)
    raise ArgumentError, "unsupported application runtime: #{runtime_mode}"
  end
  @environment = environment.to_h
  @runtime_builder = runtime_builder
  @config = nil
  @tree_shake_report = nil
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



12
13
14
# File 'lib/zui/dist_packager.rb', line 12

def config
  @config
end

#platformObject (readonly)

Returns the value of attribute platform.



12
13
14
# File 'lib/zui/dist_packager.rb', line 12

def platform
  @platform
end

#runtime_modeObject (readonly)

Returns the value of attribute runtime_mode.



12
13
14
# File 'lib/zui/dist_packager.rb', line 12

def runtime_mode
  @runtime_mode
end

#tree_shake_reportObject (readonly)

Returns the value of attribute tree_shake_report.



12
13
14
# File 'lib/zui/dist_packager.rb', line 12

def tree_shake_report
  @tree_shake_report
end

Instance Method Details

#package(source, output: nil) ⇒ Object

Raises:

  • (ArgumentError)


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
58
59
# File 'lib/zui/dist_packager.rb', line 32

def package(source, output: nil)
  project = File.expand_path(source)
  raise ArgumentError, "project directory not found: #{project}" unless File.directory?(project)

  @project = project
  @config = Dist.load(project:, platform:)
  output = File.expand_path(output || File.join(project, "dist"))
  if File.exist?(output) && !File.directory?(output)
    raise ArgumentError, "distribution output is not a directory: #{output}"
  end
  preflight!
  targets = artifact_names.map { |name| File.join(output, name) }
  existing = targets.find { |path| File.exist?(path) }
  raise ArgumentError, "distribution artifact already exists: #{existing}" if existing

  FileUtils.mkdir_p(output)
  artifacts = []
  Dir.mktmpdir(".zui-dist-", output) do |temporary|
    bundle = build_bundle(project, temporary)
    artifacts = case platform.os
                when :linux then build_linux_packages(bundle, temporary)
                when :macos then [build_macos_dmg(bundle, temporary)]
                when :windows then [build_windows_setup(bundle, temporary)]
                end
    artifacts.zip(targets).each { |source_path, target| File.rename(source_path, target) }
  end
  targets
end