-
-
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.
Add On Demand Resources Support (#6178)
* Add On Demand Resources Support * Optimize KnownAssetTagsGenerator * Remove EditAcceptanceTestAppWithOnDemandResources * Move knownAssetsGenerator to instance vars * Renaming & readme
- Loading branch information
1 parent
8411348
commit a4909f2
Showing
50 changed files
with
846 additions
and
13 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,15 @@ | ||
/// 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]? | ||
|
||
/// Returns OnDemandResourcesTags. | ||
/// - Parameter initialInstall: An array of strings that lists the tags assosiated with the Initial install tags category. | ||
/// - Parameter prefetchOrder: An array of strings that lists the tags associated with the Prefetch tag order category. | ||
/// - Returns: OnDemandResourcesTags. | ||
public static func tags(initialInstall: [String]?, prefetchOrder: [String]?) -> Self { | ||
OnDemandResourcesTags(initialInstall: initialInstall, 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
62 changes: 62 additions & 0 deletions
62
Sources/TuistGenerator/Generator/KnownAssetTagsFetcher.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,62 @@ | ||
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 KnownAssetTagsFetching: AnyObject { | ||
func fetch(project: Project) throws -> [String] | ||
} | ||
|
||
final class KnownAssetTagsFetcher: KnownAssetTagsFetching { | ||
func fetch(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 { | ||
let assetCatalogs = target.resources.resources.filter { $0.path.extension == "xcassets" } | ||
for assetCatalog in assetCatalogs { | ||
guard let children = try? assetCatalog.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.