40 lines
1.0 KiB
Swift
40 lines
1.0 KiB
Swift
import Foundation
|
|
|
|
public struct CopyFilesTask {
|
|
|
|
// MARK: Properties
|
|
|
|
private let bundleService: BundleServicing
|
|
private let fileService: FileServicing
|
|
|
|
// MARK: Initialisers
|
|
|
|
public init(
|
|
bundleService: BundleServicing? = nil,
|
|
fileService: FileServicing
|
|
) {
|
|
self.bundleService = bundleService ?? Bundle.module
|
|
self.fileService = fileService
|
|
}
|
|
|
|
// MARK: Functions
|
|
|
|
public func callAsFunction(to rootFolder: URL) async throws (FileServiceError) {
|
|
for resource in File.allCases {
|
|
guard let source = bundleService.url(
|
|
forResource: resource.rawValue,
|
|
withExtension: nil,
|
|
subdirectory: resource.resourcePath
|
|
) else {
|
|
assertionFailure("URL should have been initialized.")
|
|
return
|
|
}
|
|
|
|
let destination = rootFolder.appendingPath(resource.filePath)
|
|
|
|
try await fileService.copyFile(from: source, to: destination)
|
|
}
|
|
}
|
|
|
|
}
|