Skip to content

Commit

Permalink
Renaming & readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kapitoshka438 committed Apr 24, 2024
1 parent 8040c7a commit 6875c5b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 18 deletions.
9 changes: 6 additions & 3 deletions Sources/ProjectDescription/OnDemandResourcesTags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ public struct OnDemandResourcesTags: Codable, Equatable {
/// Prefetched tag order associated with on demand resources
public let prefetchOrder: [String]?

public init(initialInstall: [String]?, prefetchOrder: [String]?) {
self.initialInstall = initialInstall
self.prefetchOrder = prefetchOrder
/// 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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ private struct ContentJson: Decodable {
let properties: ContentProperties
}

protocol KnownAssetTagsGenerating: AnyObject {
func generate(project: Project) throws -> [String]
protocol KnownAssetTagsFetching: AnyObject {
func fetch(project: Project) throws -> [String]
}

final class KnownAssetTagsGenerator: KnownAssetTagsGenerating {
func generate(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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ final class ProjectDescriptorGenerator: ProjectDescriptorGenerating {
/// Generator for the project schemes.
let schemeDescriptorsGenerator: SchemeDescriptorsGenerating

/// Generator for the project known asset tags associated with on-demand resources.
let knownAssetTagsGenerator: KnownAssetTagsGenerating
/// Fetcher for the project known asset tags associated with on-demand resources.
let knownAssetTagsFetcher: KnownAssetTagsFetching

// MARK: - Init

Expand All @@ -65,17 +65,17 @@ final class ProjectDescriptorGenerator: ProjectDescriptorGenerating {
/// - targetGenerator: Generator for the project targets.
/// - configGenerator: Generator for the project configuration.
/// - schemeDescriptorsGenerator: Generator for the project schemes.
/// - knownAssetTagsGenerator: Generator for the project known asset tags associated with on-demand resources.
/// - knownAssetTagsFetcher: Fetcher for the project known asset tags associated with on-demand resources.
init(
targetGenerator: TargetGenerating = TargetGenerator(),
configGenerator: ConfigGenerating = ConfigGenerator(),
schemeDescriptorsGenerator: SchemeDescriptorsGenerating = SchemeDescriptorsGenerator(),
knownAssetTagsGenerator: KnownAssetTagsGenerating = KnownAssetTagsGenerator()
knownAssetTagsFetcher: KnownAssetTagsFetching = KnownAssetTagsFetcher()
) {
self.targetGenerator = targetGenerator
self.configGenerator = configGenerator
self.schemeDescriptorsGenerator = schemeDescriptorsGenerator
self.knownAssetTagsGenerator = knownAssetTagsGenerator
self.knownAssetTagsFetcher = knownAssetTagsFetcher
}

// MARK: - ProjectGenerating
Expand Down Expand Up @@ -302,7 +302,7 @@ final class ProjectDescriptorGenerator: ProjectDescriptorGenerating {
var attributes: [String: Any] = [:]

// On Demand Resources tags
if let knownAssetTags = try? knownAssetTagsGenerator.generate(project: project), !knownAssetTags.isEmpty {
if let knownAssetTags = try? knownAssetTagsFetcher.fetch(project: project), !knownAssetTags.isEmpty {
attributes["KnownAssetTags"] = knownAssetTags
}

Expand Down
7 changes: 3 additions & 4 deletions Sources/TuistGenerator/Linter/TargetLinter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,9 @@ class TargetLinter: TargetLinting {
}

private func lintOnDemandResourcesTags(target: Target) -> [LintingIssue] {
guard let odrTags = target.onDemandResourcesTags else { return [] }
guard let initialInstall = odrTags.initialInstall, let prefetchOrder = odrTags.prefetchOrder else {
return []
}
guard let onDemandResourcesTags = target.onDemandResourcesTags else { return [] }
guard let initialInstall = onDemandResourcesTags.initialInstall else { return [] }
guard let prefetchOrder = onDemandResourcesTags.prefetchOrder else { return [] }
let intersection = Set(initialInstall).intersection(Set(prefetchOrder))
return intersection.map { tag in
LintingIssue(
Expand Down
7 changes: 7 additions & 0 deletions fixtures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ An iOS application with local Swift package.

An workspace that contains an application and frameworks that leverage multiple configurations (Debug, Beta and Release) each of which also has an associated xcconfig file within `ConfigurationFiles`.

## ios_app_with_on_demand_resources

An iOS applicaiton with on-demand resources. It contains file resources and asset catalogs associated with tags which in turn are distributed between three categories:
- Initial install tags
- Prefetch tag order
- Dowloaded only on demand

## ios_app_with_remote_swift_package

An iOS application with remote Swift package.
Expand Down
2 changes: 1 addition & 1 deletion fixtures/ios_app_with_on_demand_resources/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let project = Project(
.glob(pattern: "AppWithOnDemandResources/on-demand-data.txt", tags: ["datafile"]),
],
dependencies: [],
onDemandResourcesTags: .init(
onDemandResourcesTags: .tags(
initialInstall: ["json", "data file"],
prefetchOrder: ["image-stack", "image", "tag with space"]
)
Expand Down

0 comments on commit 6875c5b

Please sign in to comment.