diff --git a/Library/Sources/Public/Models/Project.swift b/Library/Sources/Public/Models/Project.swift index 9f34306..d1505e5 100644 --- a/Library/Sources/Public/Models/Project.swift +++ b/Library/Sources/Public/Models/Project.swift @@ -1,4 +1,4 @@ -public struct Project { +public struct Project: Sendable { // MARK: Properties diff --git a/Library/Sources/Public/Tasks/RenderFilesTask.swift b/Library/Sources/Public/Tasks/RenderFilesTask.swift new file mode 100644 index 0000000..ae9500e --- /dev/null +++ b/Library/Sources/Public/Tasks/RenderFilesTask.swift @@ -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)) + } + } + +} diff --git a/Test/Sources/Cases/Internal/Enumerations/TemplateTests.swift b/Test/Sources/Cases/Internal/Enumerations/TemplateTests.swift index 85b2486..6476eed 100644 --- a/Test/Sources/Cases/Internal/Enumerations/TemplateTests.swift +++ b/Test/Sources/Cases/Internal/Enumerations/TemplateTests.swift @@ -59,6 +59,5 @@ private extension TemplateTests { .testCasesPublic, .root, ] - } } diff --git a/Test/Sources/Cases/Public/Tasks/InitGitInFolderTaskTests.swift b/Test/Sources/Cases/Public/Tasks/InitGitInFolderTaskTests.swift index 6f687de..c7ef73e 100644 --- a/Test/Sources/Cases/Public/Tasks/InitGitInFolderTaskTests.swift +++ b/Test/Sources/Cases/Public/Tasks/InitGitInFolderTaskTests.swift @@ -4,17 +4,15 @@ import Testing @testable import ColibriLibrary struct InitGitInFolderTaskTests { - - // MARK: Properties - - private let spy = TerminalServiceSpy() - - // MARK: + + // MARK: Functions tests @Test(arguments: [URL.someCurrentFolder, .someNewFolder, .someDotFolder, .someTildeFolder]) func task(at rootFolder: URL) async throws { // GIVEN - let initGitInFolder = InitGitInFolderTask(terminalService: spy) + let terminalService = TerminalServiceSpy() + + let initGitInFolder = InitGitInFolderTask(terminalService: terminalService) // WHEN try await initGitInFolder(at: rootFolder) @@ -23,10 +21,10 @@ struct InitGitInFolderTaskTests { let executableURL = URL(at: "/usr/bin/git") let pathFolder = rootFolder.pathString - #expect(spy.actions.count == 3) - #expect(spy.actions[0] == .ran(executableURL, ["init", pathFolder])) - #expect(spy.actions[1] == .ran(executableURL, ["-C", pathFolder, "add", "."])) - #expect(spy.actions[2] == .ran(executableURL, ["-C", pathFolder, "commit", "-m", "Initial commit"])) + #expect(terminalService.actions.count == 3) + #expect(terminalService.actions[0] == .ran(executableURL, ["init", pathFolder])) + #expect(terminalService.actions[1] == .ran(executableURL, ["-C", pathFolder, "add", "."])) + #expect(terminalService.actions[2] == .ran(executableURL, ["-C", pathFolder, "commit", "-m", "Initial commit"])) } }