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>
This commit was merged in pull request #4.
This commit is contained in:
2025-02-17 22:11:05 +00:00
committed by Javier Cicchelli
parent 9be8fa4a31
commit 212ca52279
33 changed files with 812 additions and 202 deletions
@@ -1,24 +1,26 @@
import Foundation
public struct InitGitInFolderTask {
// MARK: Properties
private let terminalService: TerminalServicing
// MARK: Initialisers
public init() {}
public init(terminalService: TerminalServicing) {
self.terminalService = terminalService
}
// MARK: Functions
public func callAsFunction(at rootFolder: URL) async throws (RunProcessError) {
let pathCommand = "/usr/bin/git"
public func callAsFunction(at rootFolder: URL) async throws (TerminalServiceError) {
let executableURL = URL(at: "/usr/bin/git")
let pathFolder = rootFolder.pathString
var gitInit = RunProcessTask(process: Process())
var gitAdd = RunProcessTask(process: Process())
var gitCommit = RunProcessTask(process: Process())
try await gitInit(path: pathCommand, arguments: ["init", pathFolder])
try await gitAdd(path: pathCommand, arguments: ["-C", pathFolder, "add", "."])
try await gitCommit(path: pathCommand, arguments: ["-C", pathFolder, "commit", "-m", "Initial commit"])
try await terminalService.run(executableURL, arguments: ["init", pathFolder])
try await terminalService.run(executableURL, arguments: ["-C", pathFolder, "add", "."])
try await terminalService.run(executableURL, arguments: ["-C", pathFolder, "commit", "-m", "Initial commit"])
}
}
@@ -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))
}
}
}