Skip to content

Commit

Permalink
fixed compiler error after merging main
Browse files Browse the repository at this point in the history
  • Loading branch information
Buju77 committed Aug 22, 2024
1 parent 9062a7d commit 0d08977
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 23 deletions.
8 changes: 4 additions & 4 deletions Sources/TuistKit/Services/ScaffoldService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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
Expand Down
25 changes: 15 additions & 10 deletions Sources/TuistLoader/Loaders/ManifestLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -219,14 +219,18 @@ public class ManifestLoader: ManifestLoading {
// swiftlint:disable:next function_body_length
private func loadManifest<T: Decodable>(
_ 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)
Expand Down Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
7 changes: 5 additions & 2 deletions Tests/TuistKitTests/Services/ScaffoldServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ final class ScaffoldServiceTests: TuistUnitTestCase {
// When
let options = try await subject.loadTemplateOptions(
templateName: "template",
path: nil
path: nil,
url: nil
)

// Then
Expand Down Expand Up @@ -107,7 +108,8 @@ final class ScaffoldServiceTests: TuistUnitTestCase {
// When
let options = try await subject.loadTemplateOptions(
templateName: "PluginTemplate",
path: nil
path: nil,
url: nil
)

// Then
Expand Down Expand Up @@ -269,6 +271,7 @@ extension ScaffoldService {
) async throws {
try await run(
path: path,
templateUrl: nil,
templateName: templateName,
requiredTemplateOptions: requiredTemplateOptions,
optionalTemplateOptions: optionalTemplateOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 0d08977

Please sign in to comment.