-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from FelixHerrmann/feature/package-list-revision
[Feature] Package List Revision
- Loading branch information
Showing
23 changed files
with
492 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// JSONPackageProvider.swift | ||
// SwiftPackageList | ||
// | ||
// Created by Felix Herrmann on 02.01.24. | ||
// | ||
|
||
import Foundation | ||
|
||
/// A package provider for `.json` package-lists stored in a `Bundle`. | ||
public struct JSONPackageProvider: PackageProvider { | ||
|
||
/// The bundle to read the JSON file from. | ||
/// | ||
/// Default value is `Bundle.main`. | ||
public var bundle: Bundle | ||
|
||
/// The name of the JSON file, usually specified with the `--custom-file-name` option. | ||
/// | ||
/// Default value is `"package-list"`. | ||
public var fileName: String | ||
|
||
/// Creates a JSON package provider. | ||
/// - Parameters: | ||
/// - bundle: The bundle to read the JSON file from. | ||
/// - fileName: The name of the JSON file. | ||
public init(bundle: Bundle = .main, fileName: String = "package-list") { | ||
self.bundle = bundle | ||
self.fileName = fileName | ||
} | ||
|
||
public func packages() throws -> [Package] { | ||
guard let path = bundle.path(forResource: fileName, ofType: "json") else { | ||
throw CocoaError(.fileNoSuchFile, userInfo: ["file_name": fileName, "file_type": "json"]) | ||
} | ||
let data = try Data(contentsOf: URL(fileURLWithPath: path)) | ||
let decoder = JSONDecoder() | ||
return try decoder.decode([Package].self, from: data) | ||
} | ||
} | ||
|
||
extension PackageProvider where Self == JSONPackageProvider { | ||
/// A JSON package provider. | ||
/// - Parameters: | ||
/// - bundle: The bundle to read the JSON file from. | ||
/// - fileName: The name of the JSON file. | ||
/// - Returns: A ``JSONPackageProvider`` object. | ||
public static func json(bundle: Bundle = .main, fileName: String = "package-list") -> Self { | ||
return JSONPackageProvider(bundle: bundle, fileName: fileName) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// PackageProvider.swift | ||
// SwiftPackageList | ||
// | ||
// Created by Felix Herrmann on 02.01.24. | ||
// | ||
|
||
/// A type that provides ``Package``s from some arbitrary source. | ||
public protocol PackageProvider { | ||
|
||
/// Provides the array of packages. | ||
/// - Returns: An array of ``Package`` objects. | ||
/// - Throws: This method can throw if something went wrong during the process. | ||
func packages() throws -> [Package] | ||
} |
51 changes: 51 additions & 0 deletions
51
Sources/SwiftPackageList/PropertyListPackageProvider.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// PropertyListPackageProvider.swift | ||
// SwiftPackageList | ||
// | ||
// Created by Felix Herrmann on 02.01.24. | ||
// | ||
|
||
import Foundation | ||
|
||
/// A package provider for `.plist` package-lists stored in a `Bundle`. | ||
public struct PropertyListPackageProvider: PackageProvider { | ||
|
||
/// The bundle to read the Property List file from. | ||
/// | ||
/// Default value is `Bundle.main`. | ||
public var bundle: Bundle | ||
|
||
/// The name of the Property List file, usually specified with the `--custom-file-name` option. | ||
/// | ||
/// Default value is `"package-list"`. | ||
public var fileName: String | ||
|
||
/// Creates a Property List package provider. | ||
/// - Parameters: | ||
/// - bundle: The bundle to read the Property List file from. | ||
/// - fileName: The name of the Property List file. | ||
public init(bundle: Bundle = .main, fileName: String = "package-list") { | ||
self.bundle = bundle | ||
self.fileName = fileName | ||
} | ||
|
||
public func packages() throws -> [Package] { | ||
guard let path = bundle.path(forResource: fileName, ofType: "plist") else { | ||
throw CocoaError(.fileNoSuchFile, userInfo: ["file_name": fileName, "file_type": "plist"]) | ||
} | ||
let data = try Data(contentsOf: URL(fileURLWithPath: path)) | ||
let decoder = PropertyListDecoder() | ||
return try decoder.decode([Package].self, from: data) | ||
} | ||
} | ||
|
||
extension PackageProvider where Self == PropertyListPackageProvider { | ||
/// A Property List package provider. | ||
/// - Parameters: | ||
/// - bundle: The bundle to read the Property List file from. | ||
/// - fileName: The name of the Property List file. | ||
/// - Returns: A ``PropertyListPackageProvider`` object. | ||
public static func propertyList(bundle: Bundle = .main, fileName: String = "package-list") -> Self { | ||
return PropertyListPackageProvider(bundle: bundle, fileName: fileName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
Sources/SwiftPackageListUI/SwiftUI/_AcknowledgmentsListViewModel.swift
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.