Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CocoaPods Plugins

CocoaPods Plugins

Talk about useful CocoaPods plugins and building your own, using cocoapods-packager as an example. Given at CocoaHeads Berlin, July 2014.

Boris Bügling

July 16, 2014
Tweet

More Decks by Boris Bügling

Other Decks in Technology

Transcript

  1. YO

  2. COCOAPODS-DOWNLOADER def download_head! hg! %|clone #{url} #{@target_path.shellescape}| [...] end def

    download_revision! hg! %|clone "#{url}" --rev '#{options[:revision]}' #{@target_path [...] end def download_tag! hg! %|clone "#{url}" --updaterev '#{options[:tag]}' #{@target_path [...] end
  3. CLAIDE argv = CLAide::ARGV.new(['tea', '--no-milk', '--sweetner=honey']) argv.shift_argument # => 'tea'

    argv.shift_argument # => nil argv.flag?('milk') # => false argv.flag?('milk') # => nil argv.option('sweetner') # => 'honey' argv.option('sweetner') # => nil
  4. COCOAPODS $ pod install Analyzing dependencies Pre-downloading: `DBCamera` from `https://github.com/[...]`

    Downloading dependencies Installing ARASCIISwizzle (1.1.0) Installing Bolts (1.1.0) [...] Generating Pods project Integrating client project
  5. COCOAPODS PLUGINS ▸ Add subcommands to pod, the tool ▸

    Each plugin is a Gem ▸ Same access as built-in commands
  6. WHAT? ▸ Package a Pod as a static framework ▸

    Including dependencies ▸ All supported platforms ▸ Generate a corresponding podspec
  7. TEMPLATE ▸ Just a Git repo, similar to the pod

    template ▸ Reads as much from the environment as possible ▸ Result is installable, shippable
  8. DEFINE THE COMMAND module Pod class Command class Package <

    Command self.summary = 'Package a podspec into a static library.' self.arguments = [['NAME', :required]] [...] end end end
  9. RUN def run if @spec builder = SpecBuilder.new(@spec) newspec =

    builder.spec_metadata @spec.available_platforms.each do |platform| build_in_sandbox(platform) newspec += builder.spec_platform(platform) end newspec += builder.spec_close File.open(@spec.name + '.podspec', 'w') { |file| file.write(newspec) } else help! 'Unable to find a podspec with path or name.' end end
  10. FRAGMENT OF SPECGENERATOR s.#{platform.name}.platform = :#{platform.symbolic_name}, '#{platform.deployment_target}' s.#{platform.name}.preserve_paths = '#{fwk_base}'

    s.#{platform.name}.public_header_files = '#{fwk_base}/Versions/A/Headers/*.h' s.#{platform.name}.vendored_frameworks = '#{fwk_base}'
  11. BUILD FOR A SPECIFIC PLATFORM def build_in_sandbox(platform) config.sandbox_root = 'Pods'

    config.integrate_targets = false config.skip_repo_update = true sandbox = install_pod(platform.name) UI.puts 'Building framework' xcodebuild versions_path, headers_path = create_framework_tree(platform.name.to_s) `cp #{sandbox.public_headers.root}/#{@spec.name}/*.h #{headers_path}` Pathname.new(config.sandbox_root).rmtree Pathname.new('Podfile.lock').delete end
  12. INSTALL FROM GENERATED PODFILE def install_pod(platform_name) podfile = podfile_from_spec(platform_name, @spec.deployment_target(platform_name))

    sandbox = Sandbox.new(config.sandbox_root) installer = Installer.new(sandbox, podfile) installer.install! sandbox end
  13. GENERATE THAT PODFILE def podfile_from_spec(platform_name, deployment_target) name = @spec.name path

    = @path podfile = Pod::Podfile.new do platform(platform_name, deployment_target) if path pod name, :podspec => path else pod name, :path => '.' end end podfile end
  14. ▸ Push your repo to GH ▸ Release as Ruby

    Gem ▸ Send a PR to the cocoapods.org repo
  15. !