Skip to content

Commit e7fdd59

Browse files
committed
feat(batch): add cache and concurrency options to batch command
1 parent 5935b4e commit e7fdd59

4 files changed

Lines changed: 63 additions & 4 deletions

File tree

.claude/EXFIG.toon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ commands:
6565
maxRetries: --max-retries N (default 4)
6666
resume: --resume
6767
report: --report PATH
68+
cache: --cache
69+
noCache: --no-cache
70+
force: --force
71+
cachePath: --cache-path PATH
72+
concurrentDownloads: --concurrent-downloads N (default 20)
6873

6974
download:
7075
purpose: Export Figma data as JSON

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Swift-versions](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Falexey1312%2FExFig%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/alexey1312/ExFig)
55
[![CI](https://github.com/alexey1312/ExFig/actions/workflows/ci.yml/badge.svg)](https://github.com/alexey1312/ExFig/actions/workflows/ci.yml)
66
[![Release](https://github.com/alexey1312/ExFig/actions/workflows/release.yml/badge.svg)](https://github.com/alexey1312/ExFig/actions/workflows/release.yml)
7-
![Coverage](https://img.shields.io/badge/coverage-58.52%25-yellow)
7+
![Coverage](https://img.shields.io/badge/coverage-58.51%25-yellow)
88
[![License](https://img.shields.io/github/license/alexey1312/ExFig.svg)](LICENSE)
99

1010
Command-line utility to export colors, typography, icons, and images from Figma to Xcode, Android Studio, and Flutter

Sources/ExFig/Batch/BatchConfigRunner.swift

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ protocol ConfigExportPerforming: Sendable {
1313
struct SubcommandConfigExporter: ConfigExportPerforming {
1414
let globalOptions: GlobalOptions
1515
let resume: Bool
16+
let cache: Bool
17+
let noCache: Bool
18+
let force: Bool
19+
let cachePath: String?
20+
let concurrentDownloads: Int
1621

1722
func export(
1823
configFile: ConfigFile,
@@ -21,11 +26,17 @@ struct SubcommandConfigExporter: ConfigExportPerforming {
2126
ui: TerminalUI
2227
) async throws -> ExportStats {
2328
try await InjectedClientStorage.$client.withValue(client) {
24-
let cacheOptions = CacheOptions()
29+
var cacheOptions = CacheOptions()
30+
cacheOptions.cache = cache
31+
cacheOptions.noCache = noCache
32+
cacheOptions.force = force
33+
cacheOptions.cachePath = cachePath
34+
2535
let faultToleranceOptions = FaultToleranceOptions()
2636

2737
var heavyFaultToleranceOptions = HeavyFaultToleranceOptions()
2838
heavyFaultToleranceOptions.resume = resume
39+
heavyFaultToleranceOptions.concurrentDownloads = concurrentDownloads
2940

3041
let colors = makeColors(
3142
options: options,
@@ -71,6 +82,11 @@ struct BatchConfigRunner: Sendable {
7182
let globalOptions: GlobalOptions
7283
let maxRetries: Int
7384
let resume: Bool
85+
let cache: Bool
86+
let noCache: Bool
87+
let force: Bool
88+
let cachePath: String?
89+
let concurrentDownloads: Int
7490
let exporter: any ConfigExportPerforming
7591

7692
init(
@@ -79,16 +95,31 @@ struct BatchConfigRunner: Sendable {
7995
globalOptions: GlobalOptions,
8096
maxRetries: Int,
8197
resume: Bool,
98+
cache: Bool = false,
99+
noCache: Bool = false,
100+
force: Bool = false,
101+
cachePath: String? = nil,
102+
concurrentDownloads: Int = FileDownloader.defaultMaxConcurrentDownloads,
82103
exporter: ConfigExportPerforming? = nil
83104
) {
84105
self.rateLimiter = rateLimiter
85106
self.retryPolicy = retryPolicy
86107
self.globalOptions = globalOptions
87108
self.maxRetries = maxRetries
88109
self.resume = resume
110+
self.cache = cache
111+
self.noCache = noCache
112+
self.force = force
113+
self.cachePath = cachePath
114+
self.concurrentDownloads = concurrentDownloads
89115
self.exporter = exporter ?? SubcommandConfigExporter(
90116
globalOptions: globalOptions,
91-
resume: resume
117+
resume: resume,
118+
cache: cache,
119+
noCache: noCache,
120+
force: force,
121+
cachePath: cachePath,
122+
concurrentDownloads: concurrentDownloads
92123
)
93124
}
94125

Sources/ExFig/Subcommands/Batch.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// swiftlint:disable file_length
12
import ArgumentParser
23
import FigmaAPI
34
import Foundation
@@ -44,6 +45,23 @@ extension ExFigCommand {
4445
@Option(name: .long, help: "Path to write JSON report")
4546
var report: String?
4647

48+
// Cache options
49+
@Flag(name: .long, help: "Enable version tracking cache (skip export if unchanged)")
50+
var cache: Bool = false
51+
52+
@Flag(name: .long, help: "Disable version tracking cache (always export)")
53+
var noCache: Bool = false
54+
55+
@Flag(name: .long, help: "Force export and update cache (ignore cached version)")
56+
var force: Bool = false
57+
58+
@Option(name: .long, help: "Custom path to cache file (default: .exfig-cache.json)")
59+
var cachePath: String?
60+
61+
// Download concurrency
62+
@Option(name: .long, help: "Maximum concurrent CDN downloads")
63+
var concurrentDownloads: Int = FileDownloader.defaultMaxConcurrentDownloads
64+
4765
@Argument(help: "Config files or directory to process")
4866
var paths: [String]
4967

@@ -173,7 +191,12 @@ extension ExFigCommand {
173191
retryPolicy: retryPolicy,
174192
globalOptions: globalOptions,
175193
maxRetries: maxRetries,
176-
resume: resume
194+
resume: resume,
195+
cache: cache,
196+
noCache: noCache,
197+
force: force,
198+
cachePath: cachePath,
199+
concurrentDownloads: concurrentDownloads
177200
)
178201

179202
ui.info("Processing \(configs.count) config(s) with up to \(parallel) parallel workers...")

0 commit comments

Comments
 (0)