Home

Awesome

cocoapod-to-cordova

Build tools the creates and updates a cordova plugman plugin.xml and vendored product from a cocoapod spec.

This build tool will not:

Install

cd plugin-xml-dir && mkdir -p scripts && cd scripts
git clone https://github.com/mkcode/cocoapod-to-cordova update-ios-cocoapod
cd scripts/update-ios-cocoapod
make                # For an ios release
make build-sim      # For debugging in the ios simulator
make && make clean  # Build and cleanup

Update

pod 'POD_NAME', '-> 3.2'
cd scripts/update-ios-cocoapod
make && make clean

Configuring the podfile

See http://guides.cocoapods.org/using/the-podfile.html for more info on using podfiles

Add a platform and a pod entry. See

platform :ios, '6.0'
pod 'POD_NAME', 'POD_VERSION'

Integrate CocoapodToCordovaBuilder into the post_install hook

post_install do |installer|
  require './cocoapod-to-cordova'
  build = CocoapodToCordovaBuilder.new('POD_NAME', installer.project)
  build.update_xcode_project!
end

Set the root_path and destination if they are not the defaults

  # The directory path where plugin.xml lives
  build.root_path = File.expand_path(File.join('.', '../..')) # default

  # The root installation directory. Relative to the root_path.
  build.destination = 'src/ios/vendor' #default

CocoapodToCordovaBuilder#configure can take a number of options

  build.configure({
    # Product is renamed and moved to the destination dir
    product: { name: "libmypod.a" },
    # Include the spanish localization from 'es.lproj'.
    localization: 'es',
    # Don't copy some headers. Copy the rest to 'destination/head'
    headers: { exclude: ['private_header.h', 'other_header.h'], sub_dir: 'head' },
    # Exclude this framework
    frameworks: { exclude: ['Foundation.framework'] },
    # Exclude this resource and copy the rest to 'destination/assets'
    resources: { sub_dir: 'assets', exclude: ['other-img.png'] }
  })

Cordova Notes

Examples

This tool was extracted from Cordova-DBCamera. See it in action there scripts/update-ios/cocoapod

Podfile in Cordova-DBCamera

platform :ios, '6.0'
pod 'DBCamera', git: 'git://github.com/danielebogo/dbcamera.git'

post_install do |installer|
  require './cocoapod-to-cordova'
  build = CocoapodToCordovaBuilder.new('DBCamera', installer.project)
  build.configure({
    product: { name: 'libdbcamera.a'},
    localization: 'en',
    headers: {
      exclude: [
        'DBCameraBaseCropViewController+Private.h',
        'DBCameraBaseCropViewController.h',
        'DBCameraCollectionViewController.h',
        'DBCameraCropView.h',
        'DBCameraGridView.h',
        'DBCameraLibraryViewController.h',
        'DBCameraMacros.h',
        'DBCameraManager.h',
        'DBCameraSegueViewController.h',
        'DBCollectionViewCell.h',
        'DBCollectionViewFlowLayout.h',
        'DBLibraryManager.h',
        'UIImage+Crop.h'
      ]
    }
  })
  build.update_plugin!
end

And the generated plugin.xml

<?xml version='1.0' encoding='UTF-8'?>
<plugin id='com.vulume.cordova.dbcamera' version='0.0.1' xmlns='http://apache.org/cordova/ns/plugins/1.0' xmlns:android='http://schemas.android.com/apk/res/android'>
  <name>
     dbcamera
  </name>
  <description>
     Plugman compatible wrapper for DBCamera.
  </description>
  <author>
     Chris Ewald, Vulume Inc.
  </author>
  <keywords>
     camera, ios
  </keywords>
  <license>
     MIT
  </license>
  <js-module name='dbcamera' src='www/dbcamera.js'>
    <clobbers target='cordova.plugins.dbcamera'/>
  </js-module>
  <platform name='ios'>
    <config-file parent='/*' target='config.xml'>
      <feature name='DBCamera'>
        <param name='ios-package' value='CDVdbcamera'/>
      </feature>
    </config-file>
    <source-file src='src/ios/CDVdbcamera.m'/>
    <framework src='Foundation.framework' autogen='true'/>
    <framework src='AVFoundation.framework' autogen='true'/>
    <framework src='CoreMedia.framework' autogen='true'/>
    <header-file src='src/ios/vendor/headers/DBCameraContainerViewController.h' autogen='true'/>
    <header-file src='src/ios/vendor/headers/DBCameraViewController.h' autogen='true'/>
    <header-file src='src/ios/vendor/headers/DBCameraDelegate.h' autogen='true'/>
    <header-file src='src/ios/vendor/headers/DBCameraView.h' autogen='true'/>
    <resource-file src='src/ios/vendor/resources/DBCameraImages.xcassets' autogen='true'/>
    <resource-file src='src/ios/vendor/resources/en.lproj/DBCamera.strings' autogen='true'/>
    <source-file framework='true' src='src/ios/vendor/libdbcamera.a' autogen='true'/>
  </platform>
</plugin>