diff --git a/CHANGELOG.md b/CHANGELOG.md index f25900aaa..ef38ffc47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,11 @@ _None_ [John Szumski](https://github.com/jszumski) [#1007](https://github.com/SwiftGen/SwiftGen/issues/1007) [#1008](https://github.com/SwiftGen/SwiftGen/pull/1008) + +* XCAssets: the parser now supports complicationset set, so you can use watchOS complications in asset cataloge. + [Patrick Kladek](https://github.com/Patrick-Kladek) + [#1051](https://github.com/SwiftGen/SwiftGen/pull/1051) + ### Bug Fixes diff --git a/Sources/SwiftGenKit/Parsers/AssetsCatalog/AssetsCatalogParser.swift b/Sources/SwiftGenKit/Parsers/AssetsCatalog/AssetsCatalogParser.swift index 50b0a2925..306fc63d4 100644 --- a/Sources/SwiftGenKit/Parsers/AssetsCatalog/AssetsCatalogParser.swift +++ b/Sources/SwiftGenKit/Parsers/AssetsCatalog/AssetsCatalogParser.swift @@ -18,7 +18,7 @@ public enum AssetsCatalog { self.warningHandler = warningHandler } - public static let defaultFilter = filterRegex(forExtensions: ["xcassets"]) + public static let defaultFilter = filterRegex(forExtensions: ["xcassets", "complicationset"]) public static let filterOptions: Filter.Options = [.skipsFiles, .skipsHiddenFiles, .skipsPackageDescendants] public func parse(path: Path, relativeTo parent: Path) throws { diff --git a/Sources/SwiftGenKit/Parsers/AssetsCatalog/Catalog.swift b/Sources/SwiftGenKit/Parsers/AssetsCatalog/Catalog.swift index f43badf28..8708f97da 100644 --- a/Sources/SwiftGenKit/Parsers/AssetsCatalog/Catalog.swift +++ b/Sources/SwiftGenKit/Parsers/AssetsCatalog/Catalog.swift @@ -26,7 +26,10 @@ extension AssetsCatalog.Catalog { /// This method recursively parses a directory structure, processing each folder (files are ignored). /// static func process(folder: Path, withPrefix prefix: String = "") -> [AssetsCatalogEntry] { - (try? folder.children().sorted(by: <).compactMap { path in + let children = try? folder.children() + let sorted = children?.sorted(by: <) + + return (sorted?.compactMap { path in AssetsCatalog.Entry.parse(path: path, withPrefix: prefix) }) ?? [] } diff --git a/Sources/SwiftGenKit/Parsers/AssetsCatalog/CatalogEntry.swift b/Sources/SwiftGenKit/Parsers/AssetsCatalog/CatalogEntry.swift index 6ba545afa..0258fec8d 100644 --- a/Sources/SwiftGenKit/Parsers/AssetsCatalog/CatalogEntry.swift +++ b/Sources/SwiftGenKit/Parsers/AssetsCatalog/CatalogEntry.swift @@ -92,6 +92,15 @@ extension AssetsCatalog.Entry { isNamespaced: isNamespaced, items: AssetsCatalog.Catalog.process(folder: path, withPrefix: subPrefix) ) + } else if type == "complicationset" { + print(path) + let filename = path.lastComponentWithoutExtension + + return AssetsCatalog.Entry.Group ( + name: filename, + isNamespaced: true, + items: AssetsCatalog.Catalog.process(folder: path, withPrefix: "\(prefix)\(filename)/") + ) } else { // Unknown extension return nil diff --git a/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/AppIcon (watchOS).appiconset/Contents.json b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/AppIcon (watchOS).appiconset/Contents.json index 668c89582..957a4cacc 100644 --- a/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/AppIcon (watchOS).appiconset/Contents.json +++ b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/AppIcon (watchOS).appiconset/Contents.json @@ -1,88 +1,130 @@ { "images" : [ { - "size" : "24x24", "idiom" : "watch", - "scale" : "2x", "role" : "notificationCenter", + "scale" : "2x", + "size" : "24x24", "subtype" : "38mm" }, { - "size" : "27.5x27.5", "idiom" : "watch", - "scale" : "2x", "role" : "notificationCenter", + "scale" : "2x", + "size" : "27.5x27.5", "subtype" : "42mm" }, { - "size" : "29x29", "idiom" : "watch", "role" : "companionSettings", - "scale" : "2x" + "scale" : "2x", + "size" : "29x29" }, { - "size" : "29x29", "idiom" : "watch", "role" : "companionSettings", - "scale" : "3x" + "scale" : "3x", + "size" : "29x29" }, { - "size" : "40x40", "idiom" : "watch", + "role" : "notificationCenter", "scale" : "2x", + "size" : "33x33", + "subtype" : "45mm" + }, + { + "idiom" : "watch", "role" : "appLauncher", + "scale" : "2x", + "size" : "40x40", "subtype" : "38mm" }, { - "size" : "44x44", "idiom" : "watch", - "scale" : "2x", "role" : "appLauncher", + "scale" : "2x", + "size" : "44x44", "subtype" : "40mm" }, { - "size" : "50x50", "idiom" : "watch", + "role" : "appLauncher", "scale" : "2x", + "size" : "46x46", + "subtype" : "41mm" + }, + { + "idiom" : "watch", "role" : "appLauncher", + "scale" : "2x", + "size" : "50x50", "subtype" : "44mm" }, { - "size" : "86x86", "idiom" : "watch", + "role" : "appLauncher", "scale" : "2x", + "size" : "51x51", + "subtype" : "45mm" + }, + { + "idiom" : "watch", + "role" : "appLauncher", + "scale" : "2x", + "size" : "54x54", + "subtype" : "49mm" + }, + { + "idiom" : "watch", "role" : "quickLook", + "scale" : "2x", + "size" : "86x86", "subtype" : "38mm" }, { - "size" : "98x98", "idiom" : "watch", - "scale" : "2x", "role" : "quickLook", + "scale" : "2x", + "size" : "98x98", "subtype" : "42mm" }, { + "idiom" : "watch", + "role" : "quickLook", + "scale" : "2x", "size" : "108x108", + "subtype" : "44mm" + }, + { "idiom" : "watch", + "role" : "quickLook", "scale" : "2x", + "size" : "117x117", + "subtype" : "45mm" + }, + { + "idiom" : "watch", "role" : "quickLook", - "subtype" : "44mm" + "scale" : "2x", + "size" : "129x129", + "subtype" : "49mm" }, { "idiom" : "watch-marketing", - "size" : "1024x1024", - "scale" : "1x" + "scale" : "1x", + "size" : "1024x1024" }, { - "size" : "44x44", "idiom" : "watch", - "scale" : "2x", "role" : "longLook", + "scale" : "2x", + "size" : "44x44", "subtype" : "42mm" } ], "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 } -} \ No newline at end of file +} diff --git a/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Circular.imageset/Contents.json b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Circular.imageset/Contents.json new file mode 100644 index 000000000..482a808c5 --- /dev/null +++ b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Circular.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "watch", + "scale" : "2x" + }, + { + "idiom" : "watch", + "scale" : "2x", + "screen-width" : "<=145" + }, + { + "idiom" : "watch", + "scale" : "2x", + "screen-width" : ">183" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Contents.json b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Contents.json new file mode 100644 index 000000000..e8b3252e3 --- /dev/null +++ b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Contents.json @@ -0,0 +1,53 @@ +{ + "assets" : [ + { + "filename" : "Circular.imageset", + "idiom" : "watch", + "role" : "circular" + }, + { + "filename" : "Extra Large.imageset", + "idiom" : "watch", + "role" : "extra-large" + }, + { + "filename" : "Graphic Bezel.imageset", + "idiom" : "watch", + "role" : "graphic-bezel" + }, + { + "filename" : "Graphic Circular.imageset", + "idiom" : "watch", + "role" : "graphic-circular" + }, + { + "filename" : "Graphic Corner.imageset", + "idiom" : "watch", + "role" : "graphic-corner" + }, + { + "filename" : "Graphic Extra Large.imageset", + "idiom" : "watch", + "role" : "graphic-extra-large" + }, + { + "filename" : "Graphic Large Rectangular.imageset", + "idiom" : "watch", + "role" : "graphic-large-rectangular" + }, + { + "filename" : "Modular.imageset", + "idiom" : "watch", + "role" : "modular" + }, + { + "filename" : "Utilitarian.imageset", + "idiom" : "watch", + "role" : "utilitarian" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Extra Large.imageset/Contents.json b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Extra Large.imageset/Contents.json new file mode 100644 index 000000000..482a808c5 --- /dev/null +++ b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Extra Large.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "watch", + "scale" : "2x" + }, + { + "idiom" : "watch", + "scale" : "2x", + "screen-width" : "<=145" + }, + { + "idiom" : "watch", + "scale" : "2x", + "screen-width" : ">183" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Graphic Bezel.imageset/Contents.json b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Graphic Bezel.imageset/Contents.json new file mode 100644 index 000000000..042bdc77e --- /dev/null +++ b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Graphic Bezel.imageset/Contents.json @@ -0,0 +1,17 @@ +{ + "images" : [ + { + "idiom" : "watch", + "scale" : "2x" + }, + { + "idiom" : "watch", + "scale" : "2x", + "screen-width" : ">183" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Graphic Circular.imageset/Contents.json b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Graphic Circular.imageset/Contents.json new file mode 100644 index 000000000..042bdc77e --- /dev/null +++ b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Graphic Circular.imageset/Contents.json @@ -0,0 +1,17 @@ +{ + "images" : [ + { + "idiom" : "watch", + "scale" : "2x" + }, + { + "idiom" : "watch", + "scale" : "2x", + "screen-width" : ">183" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Graphic Corner.imageset/Contents.json b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Graphic Corner.imageset/Contents.json new file mode 100644 index 000000000..042bdc77e --- /dev/null +++ b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Graphic Corner.imageset/Contents.json @@ -0,0 +1,17 @@ +{ + "images" : [ + { + "idiom" : "watch", + "scale" : "2x" + }, + { + "idiom" : "watch", + "scale" : "2x", + "screen-width" : ">183" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Graphic Extra Large.imageset/Contents.json b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Graphic Extra Large.imageset/Contents.json new file mode 100644 index 000000000..482a808c5 --- /dev/null +++ b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Graphic Extra Large.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "watch", + "scale" : "2x" + }, + { + "idiom" : "watch", + "scale" : "2x", + "screen-width" : "<=145" + }, + { + "idiom" : "watch", + "scale" : "2x", + "screen-width" : ">183" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Graphic Large Rectangular.imageset/Contents.json b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Graphic Large Rectangular.imageset/Contents.json new file mode 100644 index 000000000..042bdc77e --- /dev/null +++ b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Graphic Large Rectangular.imageset/Contents.json @@ -0,0 +1,17 @@ +{ + "images" : [ + { + "idiom" : "watch", + "scale" : "2x" + }, + { + "idiom" : "watch", + "scale" : "2x", + "screen-width" : ">183" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Modular.imageset/Contents.json b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Modular.imageset/Contents.json new file mode 100644 index 000000000..f119686d7 --- /dev/null +++ b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Modular.imageset/Contents.json @@ -0,0 +1,32 @@ +{ + "images" : [ + { + "filename" : "Modular Small Simple 38mm.png", + "idiom" : "watch", + "scale" : "2x", + "screen-width" : "<=145" + }, + { + "filename" : "Modular Small Simple 40mm and 42mm.png", + "idiom" : "watch", + "scale" : "2x", + "screen-width" : ">161" + }, + { + "filename" : "Modular Small Simple 40mm and 42mm-1.png", + "idiom" : "watch", + "scale" : "2x", + "screen-width" : ">145" + }, + { + "filename" : "Modular Small Simple 44mm.png", + "idiom" : "watch", + "scale" : "2x", + "screen-width" : ">183" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Modular.imageset/Modular Small Simple 38mm.png b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Modular.imageset/Modular Small Simple 38mm.png new file mode 100644 index 000000000..2ac1c1533 Binary files /dev/null and b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Modular.imageset/Modular Small Simple 38mm.png differ diff --git a/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Modular.imageset/Modular Small Simple 40mm and 42mm-1.png b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Modular.imageset/Modular Small Simple 40mm and 42mm-1.png new file mode 100644 index 000000000..d1bb2c7dc Binary files /dev/null and b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Modular.imageset/Modular Small Simple 40mm and 42mm-1.png differ diff --git a/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Modular.imageset/Modular Small Simple 40mm and 42mm.png b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Modular.imageset/Modular Small Simple 40mm and 42mm.png new file mode 100644 index 000000000..d1bb2c7dc Binary files /dev/null and b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Modular.imageset/Modular Small Simple 40mm and 42mm.png differ diff --git a/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Modular.imageset/Modular Small Simple 44mm.png b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Modular.imageset/Modular Small Simple 44mm.png new file mode 100644 index 000000000..c474f5861 Binary files /dev/null and b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Modular.imageset/Modular Small Simple 44mm.png differ diff --git a/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Utilitarian.imageset/Contents.json b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Utilitarian.imageset/Contents.json new file mode 100644 index 000000000..482a808c5 --- /dev/null +++ b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Complication.complicationset/Utilitarian.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "watch", + "scale" : "2x" + }, + { + "idiom" : "watch", + "scale" : "2x", + "screen-width" : "<=145" + }, + { + "idiom" : "watch", + "scale" : "2x", + "screen-width" : ">183" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Contents.json b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Contents.json index da4a164c9..73c00596a 100644 --- a/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Contents.json +++ b/Sources/TestUtils/Fixtures/Resources/XCAssets/Other.xcassets/Contents.json @@ -1,6 +1,6 @@ { "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 } -} \ No newline at end of file +} diff --git a/Sources/TestUtils/Fixtures/StencilContexts/XCAssets/all.yaml b/Sources/TestUtils/Fixtures/StencilContexts/XCAssets/all.yaml index 28594b488..ead4d05a7 100644 --- a/Sources/TestUtils/Fixtures/StencilContexts/XCAssets/all.yaml +++ b/Sources/TestUtils/Fixtures/StencilContexts/XCAssets/all.yaml @@ -61,7 +61,38 @@ catalogs: type: "image" value: "private" name: "Food" -- assets: [] +- assets: + - isNamespaced: "true" + name: "Complication" + type: "group" + items: + - name: "Circular" + type: "image" + value: "Complication/Circular" + - name: "Extra Large" + type: "image" + value: "Complication/Extra Large" + - name: "Graphic Bezel" + type: "image" + value: "Complication/Graphic Bezel" + - name: "Graphic Circular" + type: "image" + value: "Complication/Graphic Circular" + - name: "Graphic Corner" + type: "image" + value: "Complication/Graphic Corner" + - name: "Graphic Extra Large" + type: "image" + value: "Complication/Graphic Extra Large" + - name: "Graphic Large Rectangular" + type: "image" + value: "Complication/Graphic Large Rectangular" + - name: "Modular" + type: "image" + value: "Complication/Modular" + - name: "Utilitarian" + type: "image" + value: "Complication/Utilitarian" name: "Other" - assets: - isNamespaced: "true" @@ -111,5 +142,5 @@ resourceCount: arresourcegroup: 3 color: 4 data: 3 - image: 8 + image: 17 symbol: 2 diff --git a/Sources/TestUtils/Fixtures/StencilContexts/XCAssets/other.yaml b/Sources/TestUtils/Fixtures/StencilContexts/XCAssets/other.yaml new file mode 100644 index 000000000..90f86cb4a --- /dev/null +++ b/Sources/TestUtils/Fixtures/StencilContexts/XCAssets/other.yaml @@ -0,0 +1,36 @@ +catalogs: +- assets: + - isNamespaced: "true" + name: "Complication" + type: "group" + items: + - name: "Circular" + type: "image" + value: "Complication/Circular" + - name: "Extra Large" + type: "image" + value: "Complication/Extra Large" + - name: "Graphic Bezel" + type: "image" + value: "Complication/Graphic Bezel" + - name: "Graphic Circular" + type: "image" + value: "Complication/Graphic Circular" + - name: "Graphic Corner" + type: "image" + value: "Complication/Graphic Corner" + - name: "Graphic Extra Large" + type: "image" + value: "Complication/Graphic Extra Large" + - name: "Graphic Large Rectangular" + type: "image" + value: "Complication/Graphic Large Rectangular" + - name: "Modular" + type: "image" + value: "Complication/Modular" + - name: "Utilitarian" + type: "image" + value: "Complication/Utilitarian" + name: "Other" +resourceCount: + image: 9 diff --git a/Tests/SwiftGenKitTests/AssetCatalogTests.swift b/Tests/SwiftGenKitTests/AssetCatalogTests.swift index 430d83cd7..6627dfa9e 100644 --- a/Tests/SwiftGenKitTests/AssetCatalogTests.swift +++ b/Tests/SwiftGenKitTests/AssetCatalogTests.swift @@ -57,6 +57,14 @@ final class AssetCatalogTests: XCTestCase { XCTDiffContexts(result, expected: "symbols", sub: .xcassets) } + func testOther() throws { + let parser = try AssetsCatalog.Parser() + try parser.searchAndParse(path: Fixtures.resource(for: "Other.xcassets", sub: .xcassets)) + + let result = parser.stencilContext() + XCTDiffContexts(result, expected: "other", sub: .xcassets) + } + func testAll() throws { let parser = try AssetsCatalog.Parser() let paths = [