/
Workspace+ManifestMapper.swift
61 lines (53 loc) · 2.54 KB
/
Workspace+ManifestMapper.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import Foundation
import ProjectDescription
import TSCBasic
import TuistCore
import TuistGraph
import TuistSupport
extension TuistGraph.Workspace {
/// Maps a ProjectDescription.Workspace instance into a TuistGraph.Workspace model.
/// - Parameters:
/// - manifest: Manifest representation of workspace.
/// - generatorPaths: Generator paths.
static func from(
manifest: ProjectDescription.Workspace,
path: AbsolutePath,
generatorPaths: GeneratorPaths,
manifestLoader: ManifestLoading
) throws -> TuistGraph.Workspace {
func globProjects(_ path: Path) throws -> [AbsolutePath] {
let resolvedPath = try generatorPaths.resolve(path: path)
let projects = FileHandler.shared.glob(AbsolutePath.root, glob: String(resolvedPath.pathString.dropFirst()))
.lazy
.filter(FileHandler.shared.isFolder)
.filter { $0.basename != Constants.tuistDirectoryName && !$0.pathString.contains(".build/checkouts") }
.filter {
manifestLoader.manifests(at: $0).contains(where: { $0 == .package || $0 == .project })
}
if projects.isEmpty {
// FIXME: This should be done in a linter.
// Before we can do that we have to change the linters to run with the TuistCore models and not the
// ProjectDescription ones.
logger.warning("No projects found at: \(path.pathString)")
}
return Array(projects)
}
let additionalFiles = try manifest.additionalFiles.flatMap {
try TuistGraph.FileElement.from(manifest: $0, generatorPaths: generatorPaths)
}
let schemes = try manifest.schemes.map { try TuistGraph.Scheme.from(manifest: $0, generatorPaths: generatorPaths) }
let generationOptions: GenerationOptions = try .from(manifest: manifest.generationOptions, generatorPaths: generatorPaths)
let ideTemplateMacros = try manifest.fileHeaderTemplate
.map { try IDETemplateMacros.from(manifest: $0, generatorPaths: generatorPaths) }
return TuistGraph.Workspace(
path: path,
xcWorkspacePath: path.appending(component: "\(manifest.name).xcworkspace"),
name: manifest.name,
projects: try manifest.projects.flatMap(globProjects),
schemes: schemes,
generationOptions: generationOptions,
ideTemplateMacros: ideTemplateMacros,
additionalFiles: additionalFiles
)
}
}