-
-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2573944
commit f2767e3
Showing
50 changed files
with
837 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/// On-demand resources tags associated with Initial Install and Prefetched Order categories | ||
public struct OnDemandResourcesTags: Codable, Equatable { | ||
/// Initial install tags associated with on demand resources | ||
public let initialInstall: [String]? | ||
/// Prefetched tag order associated with on demand resources | ||
public let prefetchOrder: [String]? | ||
|
||
public init(initialInstall: [String]?, prefetchOrder: [String]?) { | ||
self.initialInstall = initialInstall | ||
self.prefetchOrder = prefetchOrder | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
Sources/TuistGenerator/Generator/KnownAssetTagsGenerator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import Foundation | ||
import PathKit | ||
import TuistGraph | ||
|
||
private struct ContentJson: Decodable { | ||
struct ContentProperties: Decodable { | ||
enum CodingKeys: String, CodingKey { | ||
case onDemandResourceTags = "on-demand-resource-tags" | ||
} | ||
|
||
let onDemandResourceTags: [String] | ||
} | ||
|
||
let properties: ContentProperties | ||
} | ||
|
||
protocol KnownAssetTagsGenerating: AnyObject { | ||
func generate(project: Project) throws -> [String] | ||
} | ||
|
||
final class KnownAssetTagsGenerator: KnownAssetTagsGenerating { | ||
func generate(project: Project) throws -> [String] { | ||
var tags = project.targets.map { $0.resources.resources.map(\.tags).flatMap { $0 } }.flatMap { $0 } | ||
|
||
let initialInstallTags = project.targets.compactMap { | ||
$0.onDemandResourcesTags?.initialInstall?.compactMap { $0 } | ||
}.flatMap { $0 } | ||
|
||
let prefetchOrderTags = project.targets.compactMap { | ||
$0.onDemandResourcesTags?.prefetchOrder?.compactMap { $0 } | ||
}.flatMap { $0 } | ||
|
||
tags.append(contentsOf: initialInstallTags) | ||
tags.append(contentsOf: prefetchOrderTags) | ||
|
||
var assetContentsPaths: Set<Path> = [] | ||
let decoder = JSONDecoder() | ||
for target in project.targets { | ||
for resource in target.resources.resources { | ||
guard let children = try? resource.path.path.recursiveChildren() else { continue } | ||
let contents = children.filter { $0.lastComponent == "Contents.json" } | ||
for content in contents { | ||
assetContentsPaths.insert(content) | ||
} | ||
} | ||
} | ||
|
||
var assetsTags: [String] = [] | ||
for path in assetContentsPaths { | ||
guard let data = try? Data(contentsOf: path.url) else { continue } | ||
guard let attributes = try? decoder.decode(ContentJson.self, from: data) else { continue } | ||
assetsTags.append(contentsOf: attributes.properties.onDemandResourceTags) | ||
} | ||
|
||
tags.append(contentsOf: assetsTags) | ||
|
||
let uniqueTags = Set(tags).sorted() | ||
|
||
return uniqueTags | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
public struct OnDemandResourcesTags: Codable, Equatable { | ||
public let initialInstall: [String]? | ||
public let prefetchOrder: [String]? | ||
|
||
public init(initialInstall: [String]?, prefetchOrder: [String]?) { | ||
self.initialInstall = initialInstall | ||
self.prefetchOrder = prefetchOrder | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.