Class: Zui::LiteSource

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

Constant Summary collapse

RUNTIME_FILES =
%w[
  lite_support.rb protocol.rb value.rb state_store.rb node.rb animation.rb scheduler.rb
  component_registry.rb components.rb builder.rb application.rb lite_entry.rb
].freeze
REQUIRE =
/^\s*require\s*(?:\(\s*)?["']([^"']+)["']/

Instance Method Summary collapse

Constructor Details

#initialize(project:, framework_root: FRAMEWORK_ROOT) ⇒ LiteSource

Returns a new instance of LiteSource.



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

def initialize(project:, framework_root: FRAMEWORK_ROOT)
  @project = File.expand_path(project)
  @framework_root = File.expand_path(framework_root)
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/zui/lite_source.rb', line 16

def call
  application = SourceBundle.new(
    File.join(@project, "main.rb"), root: @project, embedded_frameworks: ["zui"]
  ).call
  external = application.scan(REQUIRE).flatten.uniq
  unless external.empty?
    raise ArgumentError,
          "--lite does not support CRuby gem requires (#{external.join(', ')}); use --full"
  end

  runtime = RUNTIME_FILES.map do |name|
    path = File.join(@framework_root, "lib", "zui", name)
    raise ArgumentError, "lite runtime source is missing: #{path}" unless File.file?(path)

    source = File.readlines(path).reject { |line| REQUIRE.match?(line) }.join
    "# runtime: #{name}\n#{source}"
  end
  runtime << "module Zui\n  VERSION = #{VERSION.dump}\nend"
  runtime << application
  "#{runtime.join("\n\n")}\n"
end