Implemented the RenderFilesTask task in the library target.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
public struct Project {
|
||||
public struct Project: Sendable {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import Foundation
|
||||
|
||||
public struct RenderFilesTask {
|
||||
|
||||
// MARK: Computed
|
||||
|
||||
private let fileService: FileServicing
|
||||
private let templateService: TemplateServicing
|
||||
|
||||
// MARK: Initialisers
|
||||
|
||||
public init(
|
||||
fileService: FileServicing,
|
||||
templateService: TemplateServicing
|
||||
) {
|
||||
self.fileService = fileService
|
||||
self.templateService = templateService
|
||||
}
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
public func callAsFunction(
|
||||
at rootFolder: URL,
|
||||
with model: Project
|
||||
) async throws {
|
||||
for template in Template.allCases {
|
||||
let content = try await templateService.render(model, on: template.rawValue)
|
||||
let fileURL = rootFolder.appendingPath(template.filePath)
|
||||
|
||||
try await fileService.createFile(at: fileURL, with: Data(content.utf8))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user