cdv2spm converts a Cordova plugin.xml into a Swift Package Manager Package.swift, automating the migration from CocoaPods to SPM for iOS Cordova plugins.
Input — plugin.xml
<plugin id="com.example.myplugin" version="1.0.0">
<platform name="ios">
<podspec>
<pods>
<pod name="Alamofire" spec="~> 5.0"/>
</pods>
</podspec>
</platform>
</plugin>Output — Package.swift (with --auto-resolve)
// swift-tools-version:5.9
import PackageDescription
let package = Package(
name: "com.example.myplugin",
platforms: [.iOS(.v14)],
products: [
.library(name: "com.example.myplugin", targets: ["com.example.myplugin"])
],
dependencies: [
.package(url: "https://github.com/apache/cordova-ios.git", branch: "master"),
.package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.0.0"))
],
targets: [
.target(
name: "com.example.myplugin",
dependencies: [
.product(name: "Cordova", package: "cordova-ios"),
.product(name: "Alamofire", package: "Alamofire")
],
path: "src/ios")
]
)The tool also:
- Adds
package="swift"to the iOS platform inplugin.xml - Adds
nospm="true"to<pod>elements to preserve CocoaPods compatibility - Injects
#if canImport(Cordova)guards into Swift source files - Updates
.gitignorewith SPM build artifacts
brew tap andredestro/tap
brew install cdv2spmgit clone https://github.com/andredestro/cordova-plugin-converter.git
cd cordova-plugin-converter
make install# Convert plugin.xml in current directory
cdv2spm
# Convert with automatic CocoaPods → SPM resolution
cdv2spm --auto-resolve
# Preview changes without writing files
cdv2spm --dry-run --verbose
# Convert a specific file
cdv2spm path/to/plugin.xml| Flag | Description |
|---|---|
--auto-resolve |
Automatically convert CocoaPods dependencies to SPM equivalents |
--dry-run |
Preview changes without modifying files |
--force |
Skip all confirmation prompts |
--verbose |
Enable detailed logging output |
--no-gitignore |
Skip .gitignore updates |
--backup |
Create backups of modified files |
When --auto-resolve is used, the tool looks up each CocoaPods dependency and:
- Fetches the podspec via
pod spec cat - Finds the Git source URL and version tag
- Checks if the repository contains a
Package.swift - Converts the CocoaPods version spec to the SPM equivalent
If a dependency cannot be resolved automatically, it is added as a // TODO: comment in Package.swift for manual conversion.
MIT — see LICENSE.