feat: Fixes not creating default config directory
This commit is contained in:
@@ -117,12 +117,31 @@ struct LiveConfigurationClient {
|
||||
}
|
||||
|
||||
func generate(at file: File, force: Bool) async throws {
|
||||
@Dependency(\.logger) var logger
|
||||
|
||||
logger.debug("Begin generating configuration: \(file.path), force: \(force)")
|
||||
|
||||
let expandedPath = file.path.replacingOccurrences(
|
||||
of: "~",
|
||||
with: fileManager.homeDirectory().cleanFilePath
|
||||
)
|
||||
|
||||
let fileUrl = URL(filePath: expandedPath)
|
||||
|
||||
if !force {
|
||||
guard !fileManager.fileExists(file.url) else {
|
||||
guard !fileManager.fileExists(fileUrl) else {
|
||||
throw ConfigurationError.fileExists(path: file.path)
|
||||
}
|
||||
}
|
||||
|
||||
let fileDirectory = fileUrl.deletingLastPathComponent()
|
||||
let directoryExists = try await fileManager.isDirectory(fileDirectory)
|
||||
|
||||
if !directoryExists {
|
||||
logger.debug("Creating directory at: \(fileDirectory.cleanFilePath)")
|
||||
try await fileManager.createDirectory(fileDirectory)
|
||||
}
|
||||
|
||||
if case .toml = file {
|
||||
// In the case of toml, we copy the internal resource that includes
|
||||
// usage comments in the file.
|
||||
@@ -133,11 +152,11 @@ struct LiveConfigurationClient {
|
||||
throw ConfigurationError.resourceNotFound
|
||||
}
|
||||
|
||||
try await fileManager.copy(resourceFile, file.url)
|
||||
try await fileManager.copy(resourceFile, fileUrl)
|
||||
} else {
|
||||
// Json does not allow comments, so we write the mock configuration
|
||||
// to the file path.
|
||||
try await write(.mock, to: file, force: force)
|
||||
try await write(.mock, to: File(fileUrl)!, force: force)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user