Skip to content

Commit

Permalink
Support local, register package (#16)
Browse files Browse the repository at this point in the history
* add localSourceControl, fileSystem
* add registry
  • Loading branch information
zunda-pixel authored Aug 13, 2024
1 parent c18f224 commit f48bdd8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
12 changes: 12 additions & 0 deletions Sources/LicenseProviderExec/WorkSpacePackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct WorkSpacePackage: Decodable, Hashable {
let name: String
let location: URL
let subPath: String
let kind: Kind

enum PackageRefCodingKeys: CodingKey {
case packageRef
Expand All @@ -17,6 +18,7 @@ struct WorkSpacePackage: Decodable, Hashable {
enum CodingKeys: CodingKey {
case name
case location
case kind
}

init(from decoder: Decoder) throws {
Expand All @@ -30,5 +32,15 @@ struct WorkSpacePackage: Decodable, Hashable {

self.name = try container.decode(String.self, forKey: .name)
self.location = try container.decode(URL.self, forKey: .location)
self.kind = try container.decode(Kind.self, forKey: .kind)
}
}

extension WorkSpacePackage {
enum Kind: String, Decodable {
case remoteSourceControl
case localSourceControl
case fileSystem
case registry
}
}
18 changes: 15 additions & 3 deletions Sources/LicenseProviderExec/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,22 @@ let workspace = try JSONDecoder().decode(WorkSpace.self, from: jsonData)
var packages: [WorkSpacePackage: String] = [:]

for package in workspace.packages {
let subPath = sourcePackagesPath.appendingPathComponent("checkouts").appendingPathComponent(
package.subPath)
let subPath: URL? = switch package.kind {
case .localSourceControl, .fileSystem:
package.location
case .remoteSourceControl:
sourcePackagesPath
.appendingPathComponent("checkouts")
.appendingPathComponent(package.subPath)
case .registry:
nil
}

guard let subPath else { continue }

let contents = try FileManager.default.contentsOfDirectory(
at: subPath, includingPropertiesForKeys: nil
at: subPath,
includingPropertiesForKeys: nil
).filter { path in
let pathWithoutExtension = path.deletingPathExtension()

Expand Down

0 comments on commit f48bdd8

Please sign in to comment.