Class: Lynx::Library::Autolink

Inherits:
Object
  • Object
show all
Defined in:
lib/lynx/library/autolink.rb

Constant Summary collapse

REGISTRY_CLASS_NAME =
'LynxGeneratedLibraryRegistry'
ADDON_USE_SOURCE_NAME =
'LynxGeneratedNodeAPIAddonUse.mm'
ADDON_NAME_PATTERN =
/\A[A-Za-z0-9_.-]+\z/

Class Method Summary collapse

Class Method Details

.generate_registry(output_dir, libraries) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/lynx/library/autolink.rb', line 45

def generate_registry(output_dir, libraries)
  FileUtils.mkdir_p(output_dir)
  components = libraries.flat_map { |library| scan_components(library.source_dir) }
  node_api_addons = libraries.flat_map(&:node_api_addons)
  File.write(File.join(output_dir, "#{REGISTRY_CLASS_NAME}.h"), header_source)
  File.write(File.join(output_dir, "#{REGISTRY_CLASS_NAME}.m"),
             implementation_source(components))
  File.write(File.join(output_dir, ADDON_USE_SOURCE_NAME), addon_use_source(node_api_addons))
  File.write(File.join(output_dir, 'LynxLibraryRegistry.podspec'),
             podspec_source(node_api_addons))
  components
end

.install!(podfile, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/lynx/library/autolink.rb', line 22

def install!(podfile, options = {})
  start_dir = File.expand_path(options[:root] || Dir.pwd)
  output_dir = File.expand_path(options[:output_dir] || 'generated/lynx-library', start_dir)
  libraries = scan(start_dir)
  added_pods = []
  libraries.each do |library|
    pod_name = pod_name_from_podspec(library.podspec_path)
    add_pod_once(podfile, added_pods, pod_name, File.dirname(library.podspec_path))
    library.node_api_addons.each do |addon|
      add_pod_once(podfile, added_pods, addon.pod_name, File.dirname(addon.podspec_path))
    end
  end
  generate_registry(output_dir, libraries)
  podfile.pod 'LynxLibraryRegistry', :path => output_dir
  libraries
end

.scan(start_dir) ⇒ Object



39
40
41
42
43
# File 'lib/lynx/library/autolink.rb', line 39

def scan(start_dir)
  node_modules_dirs(start_dir).flat_map do |node_modules|
    manifest_files(node_modules).map { |manifest| parse_manifest(manifest) }.compact
  end.sort_by(&:npm_name)
end

.scan_components(source_dir) ⇒ Object



58
59
60
# File 'lib/lynx/library/autolink.rb', line 58

def scan_components(source_dir)
  source_files(source_dir).flat_map { |file| scan_source_file(file) }
end