forked from yonaskolb/XcodeGen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIconComposerSupport.swift
More file actions
98 lines (77 loc) · 4.05 KB
/
IconComposerSupport.swift
File metadata and controls
98 lines (77 loc) · 4.05 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import Foundation
import PathKit
import ProjectSpec
/// Support for IconComposer-generated asset catalogs
public struct IconComposerSupport {
/// Detects if an asset catalog contains IconComposer-generated icons
/// - Parameter assetCatalogPath: Path to the asset catalog
/// - Returns: True if the asset catalog contains IconComposer-generated icons
public static func isIconComposerGenerated(at assetCatalogPath: Path) -> Bool {
guard assetCatalogPath.isDirectory else { return false }
// Check for IconComposer-specific directory structure
let contentsPath = assetCatalogPath + "Contents.json"
guard contentsPath.exists else { return false }
// Look for IconComposer-specific patterns in the asset catalog
let children = (try? assetCatalogPath.children()) ?? []
// Check for IconComposer-specific naming patterns in app icon sets
let hasIconComposerAppIcon = children.contains { child in
guard child.extension == "appiconset" else { return false }
let name = child.lastComponent.lowercased()
return name.contains("iconcomposer") ||
name.contains("icon_composer") ||
name.contains("icon-composer") ||
name.contains("iconcomposer")
}
// Check for IconComposer-specific naming patterns in other assets
let hasIconComposerPatterns = children.contains { child in
let name = child.lastComponent.lowercased()
return name.contains("iconcomposer") ||
name.contains("icon_composer") ||
name.contains("icon-composer") ||
name.contains("iconcomposer") ||
name.contains("iconcomponents") ||
name.contains("icon_components")
}
// Check for nested icon component structure
let hasNestedIconStructure = children.contains { child in
guard child.isDirectory else { return false }
let childChildren = (try? child.children()) ?? []
return childChildren.contains { grandChild in
let name = grandChild.lastComponent.lowercased()
return name.contains("icon") && (name.contains("component") || name.contains("layer"))
}
}
return hasIconComposerAppIcon || hasIconComposerPatterns || hasNestedIconStructure
}
/// Determines the appropriate app icon name for the asset catalog
/// - Parameter assetCatalogPath: Path to the asset catalog
/// - Returns: The app icon name to use, or nil if no specific icon is found
public static func detectAppIconName(for assetCatalogPath: Path) -> String? {
guard isIconComposerGenerated(at: assetCatalogPath) else { return nil }
let children = (try? assetCatalogPath.children()) ?? []
// Look for IconComposer-specific app icon sets
for child in children {
let name = child.lastComponent.lowercased()
// Check for IconComposer-specific naming patterns
if name.contains("iconcomposer") && child.extension == "appiconset" {
return child.lastComponentWithoutExtension
}
if name.contains("icon_composer") && child.extension == "appiconset" {
return child.lastComponentWithoutExtension
}
if name.contains("icon-composer") && child.extension == "appiconset" {
return child.lastComponentWithoutExtension
}
if name.contains("iconcomposer") && child.extension == "appiconset" {
return child.lastComponentWithoutExtension
}
}
// If no specific IconComposer icon set is found, look for any app icon set
for child in children {
if child.extension == "appiconset" {
return child.lastComponentWithoutExtension
}
}
return nil
}
}