feat: Reorganizes files
This commit is contained in:
@@ -13,7 +13,6 @@ public extension DependencyValues {
|
||||
@_spi(Internal)
|
||||
@DependencyClient
|
||||
public struct FileClient: Sendable {
|
||||
public var contentsOfDirectory: @Sendable (URL) throws -> [URL]
|
||||
public var loadFile: @Sendable (URL, inout [String: String], JSONDecoder) throws -> Void
|
||||
public var homeDir: @Sendable () -> URL = { URL(string: "~/")! }
|
||||
public var isDirectory: @Sendable (URL) -> Bool = { _ in false }
|
||||
@@ -29,7 +28,6 @@ extension FileClient: DependencyKey {
|
||||
public static func live(fileManager: FileManager = .default) -> Self {
|
||||
let client = LiveFileClient(fileManager: fileManager)
|
||||
return Self(
|
||||
contentsOfDirectory: { try client.contentsOfDirectory(url: $0) },
|
||||
loadFile: { try client.loadFile(at: $0, into: &$1, decoder: $2) },
|
||||
homeDir: { client.homeDir },
|
||||
isDirectory: { client.isDirectory(url: $0) },
|
||||
@@ -64,10 +62,6 @@ private struct LiveFileClient: @unchecked Sendable {
|
||||
fileManager.isReadableFile(atPath: path(for: url))
|
||||
}
|
||||
|
||||
func contentsOfDirectory(url: URL) throws -> [URL] {
|
||||
try fileManager.contentsOfDirectory(at: url, includingPropertiesForKeys: nil)
|
||||
}
|
||||
|
||||
func fileExists(at path: String) -> Bool {
|
||||
fileManager.fileExists(atPath: path)
|
||||
}
|
||||
@@ -76,7 +70,7 @@ private struct LiveFileClient: @unchecked Sendable {
|
||||
@Dependency(\.logger) var logger
|
||||
logger.trace("Begin load file for: \(path(for: url))")
|
||||
|
||||
if url.absoluteString.contains(".json") {
|
||||
if url.absoluteString.hasSuffix(".json") {
|
||||
// Handle json file.
|
||||
let data = try Data(contentsOf: url)
|
||||
let dict = (try? decoder.decode([String: String].self, from: data)) ?? [:]
|
||||
|
||||
Reference in New Issue
Block a user