colibri/Library/Sources/Public/Tasks/RenderFilesTask.swift
Javier Cicchelli 212ca52279 Template support for input parameters (#4)
This PR contains the work done to support input parameters for the `create` command of the executable target, and to render content dynamically for the newly-generated project.

Reviewed-on: #4
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
2025-02-17 22:11:05 +00:00

35 lines
854 B
Swift

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))
}
}
}