Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions Sources/CapacitorPluginTools/PackageFileGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Sources/CommandLineTool/cap2spm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment thread
OS-pedrogustavobilro marked this conversation as resolved.

try packageGenerator.generateFile(at: podspecFileURL)

Expand Down
2 changes: 1 addition & 1 deletion Tests/CapacitorPluginToolsTests/PackageFileGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down