1+ // swiftlint:disable file_length
12import FigmaAPI
23import Foundation
34
@@ -68,13 +69,16 @@ struct SubcommandConfigExporter: ConfigExportPerforming {
6869 var allFileVersions : [ String : FileVersionInfo ] = [ : ]
6970
7071 // Only run exports for configured asset types
72+ // Each export is wrapped with asset type context for progress reporting
7173 if hasColorsConfig ( params) {
7274 let colors = makeColors (
7375 options: options,
7476 cacheOptions: cacheOptions,
7577 faultToleranceOptions: faultToleranceOptions
7678 )
77- colorsCount = try await colors. performExport ( client: client, ui: ui)
79+ colorsCount = try await BatchProgressViewStorage . $currentAssetType. withValue ( . colors) {
80+ try await colors. performExport ( client: client, ui: ui)
81+ }
7882 }
7983
8084 if hasIconsConfig ( params) {
@@ -83,7 +87,9 @@ struct SubcommandConfigExporter: ConfigExportPerforming {
8387 cacheOptions: cacheOptions,
8488 faultToleranceOptions: heavyFaultToleranceOptions
8589 )
86- let result = try await icons. performExportWithResult ( client: client, ui: ui)
90+ let result = try await BatchProgressViewStorage . $currentAssetType. withValue ( . icons) {
91+ try await icons. performExportWithResult ( client: client, ui: ui)
92+ }
8793 iconsCount = result. count
8894 allComputedHashes = mergeHashes ( allComputedHashes, result. computedHashes)
8995 allGranularStats = GranularCacheStats . merge ( allGranularStats, result. granularCacheStats)
@@ -101,7 +107,9 @@ struct SubcommandConfigExporter: ConfigExportPerforming {
101107 cacheOptions: cacheOptions,
102108 faultToleranceOptions: heavyFaultToleranceOptions
103109 )
104- let result = try await images. performExportWithResult ( client: client, ui: ui)
110+ let result = try await BatchProgressViewStorage . $currentAssetType. withValue ( . images) {
111+ try await images. performExportWithResult ( client: client, ui: ui)
112+ }
105113 imagesCount = result. count
106114 allComputedHashes = mergeHashes ( allComputedHashes, result. computedHashes)
107115 allGranularStats = GranularCacheStats . merge ( allGranularStats, result. granularCacheStats)
@@ -119,7 +127,9 @@ struct SubcommandConfigExporter: ConfigExportPerforming {
119127 cacheOptions: cacheOptions,
120128 faultToleranceOptions: faultToleranceOptions
121129 )
122- typographyCount = try await typography. performExport ( client: client, ui: ui)
130+ typographyCount = try await BatchProgressViewStorage . $currentAssetType. withValue ( . typography) {
131+ try await typography. performExport ( client: client, ui: ui)
132+ }
123133 }
124134
125135 return ExportStats (
@@ -264,6 +274,7 @@ struct BatchConfigRunner: Sendable {
264274 )
265275 }
266276
277+ // swiftlint:disable:next function_body_length
267278 func process(
268279 configFile: ConfigFile ,
269280 ui: TerminalUI ,
@@ -303,12 +314,34 @@ struct BatchConfigRunner: Sendable {
303314 }
304315 )
305316
306- let stats = try await exporter. export (
307- configFile: configFile,
308- options: options,
309- client: client,
310- ui: ui
311- )
317+ // Create progress callback that updates BatchProgressView
318+ let configName = configFile. name
319+ let callback : BatchProgressViewStorage . DownloadProgressCallback = { current, total in
320+ guard let progressView else { return }
321+ // Route to correct asset type based on current context
322+ if let assetType = BatchProgressViewStorage . currentAssetType {
323+ switch assetType {
324+ case . icons:
325+ await progressView. updateProgress ( name: configName, icons: ( current, total) )
326+ case . images:
327+ await progressView. updateProgress ( name: configName, images: ( current, total) )
328+ case . colors:
329+ await progressView. updateProgress ( name: configName, colors: ( current, total) )
330+ case . typography:
331+ await progressView. updateProgress ( name: configName, typography: ( current, total) )
332+ }
333+ }
334+ }
335+
336+ // Inject progress callback so export files can report incremental progress
337+ let stats = try await BatchProgressViewStorage . $downloadProgressCallback. withValue ( callback) {
338+ try await exporter. export (
339+ configFile: configFile,
340+ options: options,
341+ client: client,
342+ ui: ui
343+ )
344+ }
312345
313346 // Update progress view with final counts or log success
314347 if let progressView {
0 commit comments