Class: Zui::DistPackager
- Inherits:
-
Object
- Object
- Zui::DistPackager
- Defined in:
- lib/zui/dist_packager.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#platform ⇒ Object
readonly
Returns the value of attribute platform.
-
#runtime_mode ⇒ Object
readonly
Returns the value of attribute runtime_mode.
-
#tree_shake_report ⇒ Object
readonly
Returns the value of attribute tree_shake_report.
Instance Method Summary collapse
-
#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
constructor
A new instance of DistPackager.
- #package(source, output: nil) ⇒ Object
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.(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
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/zui/dist_packager.rb', line 12 def config @config end |
#platform ⇒ Object (readonly)
Returns the value of attribute platform.
12 13 14 |
# File 'lib/zui/dist_packager.rb', line 12 def platform @platform end |
#runtime_mode ⇒ Object (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_report ⇒ Object (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
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.(source) raise ArgumentError, "project directory not found: #{project}" unless File.directory?(project) @project = project @config = Dist.load(project:, platform:) output = File.(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 |