colibri/Library/Sources/Public/Tasks/CopyFilesTask.swift
Javier Cicchelli 9be8fa4a31 Basic project creation (#3)
This PR contains the work done to create a new *Hummingbird* project with very basic configuration from the _colibri_ executable, just like the project you could create with the [Hummingbird template](https://github.com/hummingbird-project/template) project in Github.

Reviewed-on: #3
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
2025-01-28 00:07:24 +00:00

40 lines
1009 B
Swift

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