-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackageFileGenerator.swift
More file actions
62 lines (56 loc) · 2.09 KB
/
Copy pathPackageFileGenerator.swift
File metadata and controls
62 lines (56 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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
let package = Package(
name: "\(packageName)",
platforms: [.iOS(.v15)],
products: [
.library(
name: "\(packageName)",
targets: ["\(targetName)"])
],
dependencies: [
.package(url: "\(capLocation)", from: "\(capVersion)")
],
targets: [
.target(
name: "\(targetName)",
dependencies: [
.product(name: "Capacitor", package: "\(capRepoName)"),
.product(name: "Cordova", package: "\(capRepoName)")
],
path: "ios/Sources/\(targetName)")\(testTargetText)
]
)
"""
}
public init(packageName: String, targetName: String, hasTests: Bool) {
self.packageName = packageName
self.targetName = targetName
self.hasTests = hasTests
}
public func generateFile(at fileURL: URL) throws {
let packageFileURL = URL(filePath: "Package.swift", directoryHint: .notDirectory, relativeTo: fileURL.baseURL)
let packageFileString = packageText
try packageFileString.write(to: packageFileURL, atomically: true, encoding: .utf8)
}
}