Class: Capacitor::Lynx::Autolink

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

Class Method Summary collapse

Class Method Details

.install!(podfile, options = {}) ⇒ Array<PluginInfo>

Declares every discovered Capacitor pod on the given Podfile.

Parameters:

  • podfile (Pod::Podfile::TargetDefinition)

    receives pod calls

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :root (String)

    where to start looking for node_modules

  • :include (Array<String>)

    only link these npm packages

  • :exclude (Array<String>)

    never link these npm packages

  • :runtime (Boolean)

    also link Capacitor/CapacitorCordova

Returns:

  • (Array<PluginInfo>)

    what was linked, in declaration order



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

def install!(podfile, options = {})
  root = File.expand_path(options[:root] || Dir.pwd)
  resolution = resolve(root, options)

  resolution[:skipped].each do |skipped|
    warn_once("[lynx-capacitor] skipping #{skipped.npm_name}: #{skipped.reason}")
  end

  resolution[:pods].each do |plugin|
    podfile.pod plugin.pod_name, :path => plugin.package_dir
  end
  resolution[:pods]
end

.resolve(root, options = {}) ⇒ Hash

The pure half of install!, so callers (and tests) can inspect what would be declared without a Podfile.

Returns:

  • (Hash)

    :pods => Array, :skipped => Array



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/capacitor/lynx/autolink.rb', line 63

def resolve(root, options = {})
  root = File.expand_path(root)
  packages = discover_packages(root)

  pods = []
  skipped = []

  if options.fetch(:runtime, true)
    runtime = packages[RUNTIME_PACKAGE]
    if runtime
      pods.concat(runtime_pods(runtime))
    else
      skipped << SkippedPackage.new(
        RUNTIME_PACKAGE,
        'not installed; declare `pod \'Capacitor\'` yourself or pass :runtime => false'
      )
    end
  end

  plugin_packages(packages, options).each do |npm_name, package_dir|
    podspec_path = find_podspec(package_dir)
    if podspec_path.nil?
      # @capacitor/motion is the standing example: published with a
      # `capacitor` key but no iOS implementation yet.
      skipped << SkippedPackage.new(npm_name, 'no iOS podspec in the package')
      next
    end
    pods << PluginInfo.new(npm_name, package_dir, real_path(package_dir),
                           pod_name_from(podspec_path), podspec_path)
  end

  { :pods => dedupe(pods, skipped), :skipped => skipped }
end