Skip to content

Commit

Permalink
Merge pull request #13 from mackoj/feat/addSupportForTests
Browse files Browse the repository at this point in the history
Add support for tests
  • Loading branch information
mackoj committed Apr 4, 2024
2 parents 52df60d + 8f4b252 commit b321968
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.7
// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -14,8 +14,8 @@ let package = Package(
targets: [
.binaryTarget(
name: "package-generator-cli",
url: "https://github.com/mackoj/PackageGeneratorCLI/releases/download/0.3.0/package-generator-cli.artifactbundle.zip",
checksum: "a411312bd07e5234578fd460c215ef63a1799f49a7aa39ac81f8b77e708ae0de"
url: "https://github.com/mackoj/PackageGeneratorCLI/releases/download/0.4.0/package-generator-cli-arm64-apple-macosx.artifactbundle.zip",
checksum: "8087731a742d7b834cdf33eb07ce11fcc054fb90c3b4f919b6080d54878d0dd5"
),
.plugin(
name: "Package Generator",
Expand Down
12 changes: 12 additions & 0 deletions Plugins/PackageGenerator/PackageGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,19 @@ struct PackageGenerator {

var isLeaf = "// [\(fakeTarget.dependencies.count)|\(fakeTarget.localDependencies)" + (fakeTarget.hasBiggestNumberOfDependencies ? "|🚛]" : "]")
if configuration.leafInfo != true { isLeaf = "" }

var test = ""
if let testInfo = fakeTarget.test {
test = """
\(spaces).testTarget(
\(spaces)\(spaces)name: "\(testInfo.name)",
\(spaces)\(spaces)path: "\(testInfo.path)"
\(spaces)),
"""
}

return """
\(test)
\(spaces).target(
\(spaces)\(spaces)name: "\(fakeTarget.name)",\(isLeaf)\(dependencies)
\(spaces)\(spaces)path: "\(fakeTarget.path)"\(otherParameters)
Expand Down
4 changes: 2 additions & 2 deletions Plugins/PackageGenerator/PackageGeneratorConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ struct PackageGeneratorConfiguration: Codable {
var leafInfo: Bool?
var exclusions: Exclusions
var headerFileURL: String?
var packageDirectories: [String]
var packageDirectories: [PackageInformation]
var targetsParameters: [String: [String]]?
var spaces: Int
var unusedThreshold: Int?
var pragmaMark: Bool

init(
headerFileURL: String? = nil,
packageDirectories: [String] = [],
packageDirectories: [PackageInformation] = [],
mappers: Mappers = Mappers(),
exclusions: Exclusions = Exclusions(),
verbose: Bool = false,
Expand Down
25 changes: 25 additions & 0 deletions Plugins/PackageGenerator/PackageInformation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Foundation

public struct PackageInformation: Codable {
public struct PathInfo: Codable {
public let path: String
public let name: String
}
public let test: PathInfo?
public let target: PathInfo

public init(from decoder: any Decoder) throws {
// Legacy Parser
let stringContainer = try decoder.singleValueContainer()
if let pathString = try? stringContainer.decode(String.self) {
let path = URL(fileURLWithPath: pathString)
self.target = PathInfo(path: pathString, name: path.lastPathComponent)
self.test = nil
return
}

let container = try decoder.container(keyedBy: CodingKeys.self)
self.test = try container.decodeIfPresent(PackageInformation.PathInfo.self, forKey: .test)
self.target = try container.decode(PackageInformation.PathInfo.self, forKey: .target)
}
}
35 changes: 26 additions & 9 deletions Plugins/PackageGenerator/ParsedPackage.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import Foundation

struct ParsedPackage: Codable, CustomStringConvertible {
var name: String
var dependencies: [String]
var path: String
var fullPath: String
var localDependencies: Int = 0
var hasBiggestNumberOfDependencies: Bool = false
public struct ParsedPackage: Codable, CustomStringConvertible {
public var name: String
public var test: PackageInformation.PathInfo?
public var dependencies: [String]
public var path: String
public var fullPath: String
public var resources: String?
public var localDependencies: Int = 0
public var hasBiggestNumberOfDependencies: Bool = false

var description: String {
"[\(dependencies.count)|\(localDependencies)] \(name)"
public var hasResources: Bool {
resources != nil && resources!.isEmpty == false
}

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

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

0 comments on commit b321968

Please sign in to comment.