Skip to content

Commit c32e4a8

Browse files
committed
refactor(xcassets): extract XCAssetCompiler to xtool-org/AssetKit
Drops in-tree Sources/XCAssetCompiler and its tests; depends on xtool-org/AssetKit 1.0.0 instead. Packer adapts to the new CompileResult / appIconBundle API.
1 parent c4f4225 commit c32e4a8

37 files changed

Lines changed: 21 additions & 2617 deletions

Package.resolved

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ let package = Package(
4343
.package(url: "https://github.com/xtool-org/xtool-core", .upToNextMinor(from: "1.4.0")),
4444
.package(url: "https://github.com/xtool-org/SwiftyMobileDevice", .upToNextMinor(from: "1.5.0")),
4545
.package(url: "https://github.com/xtool-org/zsign", .upToNextMinor(from: "1.7.0")),
46+
.package(url: "https://github.com/xtool-org/AssetKit", .upToNextMinor(from: "1.0.0")),
4647

4748
.package(url: "https://github.com/apple/swift-system", from: "1.4.0"),
4849
.package(url: "https://github.com/apple/swift-http-types", from: "1.3.1"),
@@ -67,7 +68,6 @@ let package = Package(
6768
.package(url: "https://github.com/mxcl/Version", from: "2.1.0"),
6869
.package(url: "https://github.com/jpsim/Yams", from: "5.1.3"),
6970
.package(url: "https://github.com/saagarjha/unxip", from: "3.2.0"),
70-
.package(url: "https://github.com/tayloraswift/swift-png", from: "4.5.0"),
7171

7272
// TODO: just depend on tuist/XcodeProj instead
7373
.package(url: "https://github.com/yonaskolb/XcodeGen", from: "2.45.4"),
@@ -171,27 +171,11 @@ let package = Package(
171171
name: "PackLib",
172172
dependencies: [
173173
"XUtils",
174-
"XCAssetCompiler",
174+
.product(name: "AssetKit", package: "AssetKit"),
175175
.product(name: "Yams", package: "Yams"),
176176
.product(name: "XcodeGenKit", package: "XcodeGen", condition: .when(platforms: [.macOS])),
177177
]
178178
),
179-
.target(
180-
name: "XCAssetCompiler",
181-
dependencies: [
182-
"XUtils",
183-
.product(name: "PNG", package: "swift-png"),
184-
]
185-
),
186-
.testTarget(
187-
name: "XCAssetCompilerTests",
188-
dependencies: [
189-
"XCAssetCompiler",
190-
],
191-
resources: [
192-
.copy("Fixtures"),
193-
]
194-
),
195179
.executableTarget(
196180
name: "xtool",
197181
dependencies: [

Sources/PackLib/Packer.swift

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22
import XUtils
3-
import XCAssetCompiler
3+
import AssetKit
44

55
public struct Packer: Sendable {
66
public let buildSettings: BuildSettings
@@ -125,19 +125,16 @@ public struct Packer: Sendable {
125125
) async throws {
126126
try? FileManager.default.createDirectory(at: outputURL, withIntermediateDirectories: true)
127127

128-
let compiled: CompiledCatalog?
128+
let compiled: CompileResult?
129129
if let catalogPath = product.assetCatalogPath {
130-
let compiler = XCAssetCompiler(
131-
deploymentTarget: product.deploymentTarget,
132-
diagnostics: diagnostics
133-
)
130+
let compiler = XCAssetCompiler(deploymentTarget: product.deploymentTarget)
134131
compiled = try await compiler.compile(catalog: URL(fileURLWithPath: catalogPath))
135132
} else {
136133
compiled = nil
137134
}
138135

139136
let effectiveIconPath: String?
140-
if let compiled, compiled.primaryIconName != nil {
137+
if let compiled, compiled.appIconBundle != nil {
141138
if product.iconPath != nil {
142139
await diagnostics.warn(
143140
"xtool.yml: iconPath is ignored because the asset catalog supplies an AppIcon."
@@ -208,9 +205,9 @@ public struct Packer: Sendable {
208205
try carData.write(to: destURL)
209206
try Task.checkCancellation()
210207
}
211-
for emittedFile in compiled.emittedFiles {
212-
let name = emittedFile.name
213-
let data = emittedFile.data
208+
for looseFile in compiled.appIconBundle?.looseFiles ?? [] {
209+
let name = looseFile.name
210+
let data = looseFile.data
214211
group.addTask {
215212
let destURL = outputURL.appendingPathComponent(name)
216213
try data.write(to: destURL)
@@ -230,8 +227,8 @@ public struct Packer: Sendable {
230227
info["CFBundleSupportedPlatforms"] = ["iPhoneOS"]
231228
}
232229

233-
if let compiled {
234-
info.merge(compiled.infoPlistAdditions, uniquingKeysWith: { _, new in new })
230+
if let bundle = compiled?.appIconBundle {
231+
info.merge(bundle.infoPlistAdditions, uniquingKeysWith: { _, new in new })
235232
}
236233

237234
if let iconPath = effectiveIconPath {

Sources/XCAssetCompiler/AppIcon/AppIconPlist.swift

Lines changed: 0 additions & 97 deletions
This file was deleted.

Sources/XCAssetCompiler/BOM/BOMTree.swift

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)