Skip to content

Commit

Permalink
Merge pull request #14 from mackoj/feat/testTargetImports
Browse files Browse the repository at this point in the history
Add support for test imports
  • Loading branch information
mackoj authored May 3, 2024
2 parents 736b245 + 3604f22 commit 11eed5d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ let package = Package(
targets: [
.binaryTarget(
name: "package-generator-cli",
url: "https://github.com/mackoj/PackageGeneratorCLI/releases/download/0.4.2/package-generator-cli-arm64-apple-macosx.artifactbundle.zip",
checksum: "ddf169bfe8b9260d40069671b8e7282b2655679d2b404d080af2a3935025fb7f"
url: "https://github.com/mackoj/PackageGeneratorCLI/releases/download/0.5.0/package-generator-cli-arm64-apple-macosx.artifactbundle.zip",
checksum: "8ffa941438b678085c45e6caab195cdb0a6b4a6fb6e4425589869a1a2dc1e8da"
),
.plugin(
name: "Package Generator",
Expand All @@ -29,7 +29,7 @@ let package = Package(
]
),
dependencies: [
.target(name: "package-generator-cli")
.target(name: "package-generator-cli"),
],
path: "Plugins/PackageGenerator"
),
Expand Down
19 changes: 16 additions & 3 deletions Plugins/PackageGenerator/PackageGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct PackageGenerator {
}

if config.verbose {
print("package-generator-cli", cliArguments.joined(separator: " "))
print("swift run package-generator-cli", cliArguments.map {"\""+$0+"\""}.joined(separator: " "))
}

runCli(
Expand Down Expand Up @@ -96,6 +96,13 @@ struct PackageGenerator {
localDependencies.removeAll(where: config.exclusions.imports.contains(_:))
localDependencies.sort(by: <)
parsedPackage.dependencies = localDependencies

localDependencies = parsedPackage.testDependencies
localDependencies.removeAll(where: config.exclusions.apple.contains(_:))
localDependencies.removeAll(where: config.exclusions.imports.contains(_:))
localDependencies.sort(by: <)
parsedPackage.testDependencies = localDependencies

parsedPackage.name = config.mappers.targets[parsedPackage.path, default: parsedPackage.name]
if config.exclusions.targets.contains(parsedPackage.name) == false {
parsedPackages.append(parsedPackage)
Expand Down Expand Up @@ -365,7 +372,13 @@ struct PackageGenerator {
if localDependencies.isEmpty == false {
dependencies = "\n\(spaces)\(spaces)dependencies: [\n" + localDependencies.map{ "\(spaces)\(spaces)\(spaces)\(configuration.mappers.imports[$0, default: "\"\($0)\""])" }.sorted(by: <).joined(separator: ",\n") + "\n\(spaces)\(spaces)],"
}


let localTestDependencies = fakeTarget.testDependencies
var testDependencies = ""
if localTestDependencies.isEmpty == false {
testDependencies = "\n\(spaces)\(spaces)dependencies: [\n" + localTestDependencies.map{ "\(spaces)\(spaces)\(spaces)\(configuration.mappers.imports[$0, default: "\"\($0)\""])" }.sorted(by: <).joined(separator: ",\n") + "\n\(spaces)\(spaces)],"
}

var otherParameters = ""
if let targetParameters = configuration.targetsParameters?[fakeTarget.name], targetParameters.isEmpty == false {
otherParameters = ",\n" + targetParameters.map { "\(spaces)\(spaces)\($0)" } .joined(separator: ",\n")
Expand All @@ -378,7 +391,7 @@ struct PackageGenerator {
if let testInfo = fakeTarget.test {
test = """
\(spaces).testTarget(
\(spaces)\(spaces)name: "\(testInfo.name)",
\(spaces)\(spaces)name: "\(testInfo.name)",\(testDependencies)
\(spaces)\(spaces)path: "\(testInfo.path)"
\(spaces)),
"""
Expand Down
9 changes: 7 additions & 2 deletions Plugins/PackageGenerator/ParsedPackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public struct ParsedPackage: Codable, CustomStringConvertible {
public var name: String
public var test: PackageInformation.PathInfo?
public var dependencies: [String]
public var testDependencies: [String]
public var path: String
public var fullPath: String
public var resources: String?
Expand All @@ -15,13 +16,17 @@ public struct ParsedPackage: Codable, CustomStringConvertible {
}

public var description: String {
"[\(dependencies.count)|\(localDependencies)] \(name) \(hasResources == false ? "" : "/ hasResources")"
if testDependencies.isEmpty {
return "[\(dependencies.count)|\(localDependencies)] \(name) \(hasResources == false ? "" : "/ hasResources")"
}
return "[\(testDependencies.count)|\(localDependencies)] \(name)"
}

public init(name: String, test: PackageInformation.PathInfo? = nil, dependencies: [String], path: String, fullPath: String, resources: String? = nil, localDependencies: Int = 0, hasBiggestNumberOfDependencies: Bool = false) {
public init(name: String, test: PackageInformation.PathInfo? = nil, dependencies: [String], testDependencies: [String], path: String, fullPath: String, resources: String? = nil, localDependencies: Int = 0, hasBiggestNumberOfDependencies: Bool = false) {
self.name = name
self.test = test
self.dependencies = dependencies
self.testDependencies = testDependencies
self.path = path
self.fullPath = fullPath
self.resources = resources
Expand Down

0 comments on commit 11eed5d

Please sign in to comment.