diff --git a/Sources/CapacitorPluginTools/PackageFileGenerator.swift b/Sources/CapacitorPluginTools/PackageFileGenerator.swift index ebe3bae..2a099e6 100644 --- a/Sources/CapacitorPluginTools/PackageFileGenerator.swift +++ b/Sources/CapacitorPluginTools/PackageFileGenerator.swift @@ -3,11 +3,22 @@ import Foundation public class PackageFileGenerator { let packageName: String let targetName: String + let hasTests: Bool let capRepoName = "capacitor-swift-pm" let capLocation = "https://github.com/ionic-team/capacitor-swift-pm.git" let capVersion = "8.0.0" var packageText: String { + var testTargetText = "" + if hasTests { + testTargetText = """ + , + .testTarget( + name: "\(targetName)Tests", + dependencies: ["\(targetName)"], + path: "ios/Tests/\(targetName)Tests") + """ + } return """ // swift-tools-version: 5.9 import PackageDescription @@ -30,19 +41,16 @@ public class PackageFileGenerator { .product(name: "Capacitor", package: "\(capRepoName)"), .product(name: "Cordova", package: "\(capRepoName)") ], - path: "ios/Sources/\(targetName)"), - .testTarget( - name: "\(targetName)Tests", - dependencies: ["\(targetName)"], - path: "ios/Tests/\(targetName)Tests") + path: "ios/Sources/\(targetName)")\(testTargetText) ] ) """ } - public init(packageName: String, targetName: String) { + public init(packageName: String, targetName: String, hasTests: Bool) { self.packageName = packageName self.targetName = targetName + self.hasTests = hasTests } public func generateFile(at fileURL: URL) throws { diff --git a/Sources/CommandLineTool/cap2spm.swift b/Sources/CommandLineTool/cap2spm.swift index 617a2a5..8726096 100644 --- a/Sources/CommandLineTool/cap2spm.swift +++ b/Sources/CommandLineTool/cap2spm.swift @@ -50,7 +50,7 @@ struct Cap2SPM: ParsableCommand { try? modifyTestsFile(at: swiftTestsFileURL, with: capPlugin.identifier) } - let packageGenerator = PackageFileGenerator(packageName: podspec.podName, targetName: capPlugin.identifier) + let packageGenerator = PackageFileGenerator(packageName: podspec.podName, targetName: capPlugin.identifier, hasTests: swiftTestsFileURL != nil) try packageGenerator.generateFile(at: podspecFileURL) diff --git a/Tests/CapacitorPluginToolsTests/PackageFileGenerator.swift b/Tests/CapacitorPluginToolsTests/PackageFileGenerator.swift index 9db058b..0ad3071 100644 --- a/Tests/CapacitorPluginToolsTests/PackageFileGenerator.swift +++ b/Tests/CapacitorPluginToolsTests/PackageFileGenerator.swift @@ -6,7 +6,7 @@ struct PackageFileGeneratorTests { let packageFileGenerator: PackageFileGenerator init() { - packageFileGenerator = PackageFileGenerator(packageName: "CapacitorAppPlugin", targetName: "AppPlugin") + packageFileGenerator = PackageFileGenerator(packageName: "CapacitorAppPlugin", targetName: "AppPlugin", hasTests: true) } @Test("Generates expected Package.swift Text")