diff --git a/Sources/TuistKit/Services/ScaffoldService.swift b/Sources/TuistKit/Services/ScaffoldService.swift index dba3008d19d..3e43367ba07 100644 --- a/Sources/TuistKit/Services/ScaffoldService.swift +++ b/Sources/TuistKit/Services/ScaffoldService.swift @@ -68,7 +68,7 @@ final class ScaffoldService { var attributes: [Template.Attribute] = [] if let templateUrl = url, templateUrl.isGitURL { - try await templateGitLoader.loadTemplate(from: templateUrl, templateName: templateName, plugins: plugins) { template in + try await templateGitLoader.loadTemplate(from: templateUrl, templateName: templateName) { template in attributes = template.attributes } } else { @@ -80,7 +80,7 @@ final class ScaffoldService { let template = try await templateLoader.loadTemplate(at: templateDirectory, plugins: plugins) attributes = template.attributes } - return template.attributes.reduce(into: (required: [], optional: [])) { currentValue, attribute in + return attributes.reduce(into: (required: [], optional: [])) { currentValue, attribute in switch attribute { case let .optional(name, default: _): currentValue.optional.append(name) @@ -102,13 +102,13 @@ final class ScaffoldService { if let templateUrl = templateUrl, templateUrl.isGitURL { try await templateGitLoader.loadTemplate(from: templateUrl, templateName: templateName, closure: { template in - let parsedAttributes = try parseAttributes( + let parsedAttributes = try self.parseAttributes( requiredTemplateOptions: requiredTemplateOptions, optionalTemplateOptions: optionalTemplateOptions, template: template ) - try await templateGenerator.generate( + try await self.templateGenerator.generate( template: template, to: path, attributes: parsedAttributes diff --git a/Sources/TuistLoader/Loaders/ManifestLoader.swift b/Sources/TuistLoader/Loaders/ManifestLoader.swift index 6db6f8a456d..4214d1e8569 100644 --- a/Sources/TuistLoader/Loaders/ManifestLoader.swift +++ b/Sources/TuistLoader/Loaders/ManifestLoader.swift @@ -167,12 +167,12 @@ public class ManifestLoader: ManifestLoading { return !manifests.isDisjoint(with: rootManifests) } - public func loadProject(at path: AbsolutePath) throws -> ProjectDescription.Project { - try loadManifest(.project, at: path) + public func loadConfig(at path: AbsolutePath) async throws -> ProjectDescription.Config { + try await loadManifest(.config, at: path) } - public func loadProject(at path: AbsolutePath) async throws -> ProjectDescription.Project { - try await loadManifest(.project, at: path) + public func loadProject(at path: AbsolutePath, rootPath: AbsolutePath? = nil) async throws -> ProjectDescription.Project { + try await loadManifest(.project, at: path, rootPath: rootPath) } public func loadWorkspace(at path: AbsolutePath) async throws -> ProjectDescription.Workspace { @@ -219,14 +219,18 @@ public class ManifestLoader: ManifestLoading { // swiftlint:disable:next function_body_length private func loadManifest( _ manifest: Manifest, - at path: AbsolutePath - ) throws -> T { + at path: AbsolutePath, + rootPath: AbsolutePath? = nil + ) async throws -> T { let manifestPath = try manifestPath( manifest, at: path ) - let data = try loadDataForManifest(manifest, at: manifestPath) + // build root manifest file path + let rootManifestPath = try rootManifestPath(manifest, at: rootPath) + + let data = try await loadDataForManifest(manifest, at: manifestPath, rootPath: rootManifestPath) do { return try decoder.decode(T.self, from: data) @@ -314,9 +318,10 @@ public class ManifestLoader: ManifestLoading { private func loadDataForManifest( _ manifest: Manifest, - at path: AbsolutePath - ) throws -> Data { - let arguments = try buildArguments( + at path: AbsolutePath, + rootPath: AbsolutePath? = nil + ) async throws -> Data { + let arguments = try await buildArguments( manifest, at: path ) + ["--tuist-dump"] diff --git a/Sources/TuistLoaderTesting/Loaders/Mocks/MockTemplateGitLoader.swift b/Sources/TuistLoaderTesting/Loaders/Mocks/MockTemplateGitLoader.swift index da4ef5f2119..ee8507059cd 100644 --- a/Sources/TuistLoaderTesting/Loaders/Mocks/MockTemplateGitLoader.swift +++ b/Sources/TuistLoaderTesting/Loaders/Mocks/MockTemplateGitLoader.swift @@ -5,7 +5,7 @@ import TuistLoader public final class MockTemplateGitLoader: TemplateGitLoading { public var loadTemplateStub: ((String) throws -> Template)? - public func loadTemplate(from templateURL: String, closure: @escaping (Template) async throws -> Void) async throws { + public func loadTemplate(from templateURL: String, templateName: String, closure: @escaping (Template) async throws -> Void) async throws { let template = try loadTemplateStub?(templateURL) ?? Template(description: "", attributes: [], items: []) try await closure(template) } diff --git a/Tests/TuistKitTests/Services/ScaffoldServiceTests.swift b/Tests/TuistKitTests/Services/ScaffoldServiceTests.swift index f0ac7dfc5e5..440c28d60e9 100644 --- a/Tests/TuistKitTests/Services/ScaffoldServiceTests.swift +++ b/Tests/TuistKitTests/Services/ScaffoldServiceTests.swift @@ -72,7 +72,8 @@ final class ScaffoldServiceTests: TuistUnitTestCase { // When let options = try await subject.loadTemplateOptions( templateName: "template", - path: nil + path: nil, + url: nil ) // Then @@ -107,7 +108,8 @@ final class ScaffoldServiceTests: TuistUnitTestCase { // When let options = try await subject.loadTemplateOptions( templateName: "PluginTemplate", - path: nil + path: nil, + url: nil ) // Then @@ -269,6 +271,7 @@ extension ScaffoldService { ) async throws { try await run( path: path, + templateUrl: nil, templateName: templateName, requiredTemplateOptions: requiredTemplateOptions, optionalTemplateOptions: optionalTemplateOptions diff --git a/Tests/TuistLoaderTests/Loaders/CachedManifestLoaderTests.swift b/Tests/TuistLoaderTests/Loaders/CachedManifestLoaderTests.swift index 2b4a54e9aaf..2402c53ae40 100644 --- a/Tests/TuistLoaderTests/Loaders/CachedManifestLoaderTests.swift +++ b/Tests/TuistLoaderTests/Loaders/CachedManifestLoaderTests.swift @@ -60,8 +60,8 @@ final class CachedManifestLoaderTests: TuistUnitTestCase { } given(manifestLoader) - .loadProject(at: .any) - .willProduce { [unowned self] path in + .loadProject(at: .any, rootPath: .any) + .willProduce { [unowned self] path, rootPath in guard let manifest = projectManifests[path] else { throw ManifestLoaderError.manifestNotFound(.project, path) } diff --git a/Tests/TuistLoaderTests/Loaders/ManifestModelConverterTests.swift b/Tests/TuistLoaderTests/Loaders/ManifestModelConverterTests.swift index 8ef1e45f92a..77e9838d652 100644 --- a/Tests/TuistLoaderTests/Loaders/ManifestModelConverterTests.swift +++ b/Tests/TuistLoaderTests/Loaders/ManifestModelConverterTests.swift @@ -323,8 +323,8 @@ class ManifestModelConverterTests: TuistUnitTestCase { ) -> ManifestLoading { let manifestLoader = MockManifestLoading() given(manifestLoader) - .loadProject(at: .any) - .willProduce { path in + .loadProject(at: .any, rootPath: .any) + .willProduce { path, rootPath in guard let manifest = projects[path] else { throw ManifestLoaderError.manifestNotFound(path) } diff --git a/Tests/TuistLoaderTests/Loaders/RecursiveManifestLoaderTests.swift b/Tests/TuistLoaderTests/Loaders/RecursiveManifestLoaderTests.swift index fd7549d9db3..8b760656663 100644 --- a/Tests/TuistLoaderTests/Loaders/RecursiveManifestLoaderTests.swift +++ b/Tests/TuistLoaderTests/Loaders/RecursiveManifestLoaderTests.swift @@ -395,8 +395,8 @@ final class RecursiveManifestLoaderTests: TuistUnitTestCase { private func createManifestLoader() -> MockManifestLoading { let manifestLoader = MockManifestLoading() given(manifestLoader) - .loadProject(at: .any) - .willProduce { [unowned self] path in + .loadProject(at: .any, rootPath: .any) + .willProduce { [unowned self] path, rootPath in guard let manifest = projectManifests[path] else { throw ManifestLoaderError.manifestNotFound(.project, path) }