feat: Begins vault commands, adds nodes for rendering discussion documentation.
This commit is contained in:
@@ -18,6 +18,7 @@ public struct FileClient: Sendable {
|
||||
public var isDirectory: @Sendable (URL) -> Bool = { _ in false }
|
||||
public var isReadable: @Sendable (URL) -> Bool = { _ in false }
|
||||
public var fileExists: @Sendable (String) -> Bool = { _ in false }
|
||||
public var findVaultFileInCurrentDirectory: @Sendable () throws -> URL?
|
||||
public var write: @Sendable (String, Data) throws -> Void
|
||||
}
|
||||
|
||||
@@ -33,6 +34,7 @@ extension FileClient: DependencyKey {
|
||||
isDirectory: { client.isDirectory(url: $0) },
|
||||
isReadable: { client.isReadable(url: $0) },
|
||||
fileExists: { client.fileExists(at: $0) },
|
||||
findVaultFileInCurrentDirectory: { try client.findVaultFileInCurrentDirectory() },
|
||||
write: { path, data in
|
||||
try data.write(to: URL(filePath: path))
|
||||
}
|
||||
@@ -66,6 +68,31 @@ private struct LiveFileClient: @unchecked Sendable {
|
||||
fileManager.fileExists(atPath: path)
|
||||
}
|
||||
|
||||
func findVaultFileInCurrentDirectory() throws -> URL? {
|
||||
let urls = try fileManager.contentsOfDirectory(at: URL(filePath: "."), includingPropertiesForKeys: nil)
|
||||
|
||||
if let vault = urls.firstVaultFile {
|
||||
return vault
|
||||
}
|
||||
|
||||
// check for folders that end with "vars" and search those next.
|
||||
for folder in urls.filter({ $0.absoluteString.hasSuffix("vars/") }) {
|
||||
let files = try fileManager.contentsOfDirectory(at: folder, includingPropertiesForKeys: nil)
|
||||
if let vault = files.firstVaultFile {
|
||||
return vault
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to check all sub-folders
|
||||
for folder in urls.filter({ self.isDirectory(url: $0) && !$0.absoluteString.hasSuffix("vars/") }) {
|
||||
let files = try fileManager.contentsOfDirectory(at: folder, includingPropertiesForKeys: nil)
|
||||
if let vault = files.firstVaultFile {
|
||||
return vault
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadFile(at url: URL, into env: inout [String: String], decoder: JSONDecoder) throws {
|
||||
@Dependency(\.logger) var logger
|
||||
logger.trace("Begin load file for: \(path(for: url))")
|
||||
@@ -101,3 +128,9 @@ private struct LiveFileClient: @unchecked Sendable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension Array where Element == URL {
|
||||
var firstVaultFile: URL? {
|
||||
first { $0.absoluteString.hasSuffix("vault.yml") }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user