Implemented the RenderFilesTask task in the library target.

This commit is contained in:
2025-02-08 12:55:31 +01:00
parent 5f5f902773
commit 94e6070091
4 changed files with 44 additions and 13 deletions
+1 -1
View File
@@ -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))
}
}
}