diff --git a/Sources/FigmaGen/Providers/Images/Assets/DefaultImageAssetsProvider.swift b/Sources/FigmaGen/Providers/Images/Assets/DefaultImageAssetsProvider.swift index 665fc12..0c9b29e 100644 --- a/Sources/FigmaGen/Providers/Images/Assets/DefaultImageAssetsProvider.swift +++ b/Sources/FigmaGen/Providers/Images/Assets/DefaultImageAssetsProvider.swift @@ -38,31 +38,30 @@ final class DefaultImageAssetsProvider: ImageAssetsProvider, ImagesFolderPathRes private func makeAsset( for node: ImageRenderedNode, setNode: ImageComponentSetRenderedNode, - format: ImageFormat, - preserveVectorData: Bool, - groupByFrame: Bool, - namingStyle: ImageNamingStyle, + parameters: ImagesParameters, folderPath: Path ) -> ImageAsset { - let name = resolveName(for: node, setNode: setNode, namingStyle: namingStyle) - let folderPath = resolveFolderPath(groupByFrame: groupByFrame, setNode: setNode, folderPath: folderPath) + let name = resolveName(for: node, setNode: setNode, namingStyle: parameters.namingStyle) + + let folderPath = resolveFolderPath( + groupByFrame: parameters.groupByFrame, + setNode: setNode, + folderPath: folderPath + ) let filePaths = node.urls.keys.reduce(into: [:]) { result, scale in result[scale] = folderPath .appending(fileName: name, extension: AssetImageSet.pathExtension) - .appending(fileName: name.appending(scale.fileNameSuffix), extension: format.fileExtension) + .appending(fileName: name.appending(scale.fileNameSuffix), extension: parameters.format.fileExtension) .string } - return ImageAsset(name: name, filePaths: filePaths, preserveVectorData: preserveVectorData) + return ImageAsset(name: name, filePaths: filePaths, preserveVectorData: parameters.preserveVectorData) } private func makeAssets( for nodes: [ImageComponentSetRenderedNode], - format: ImageFormat, - preserveVectorData: Bool, - groupByFrame: Bool, - namingStyle: ImageNamingStyle, + parameters: ImagesParameters, folderPath: Path ) -> [ImageComponentSetAsset] { nodes.map { setNode in @@ -72,10 +71,7 @@ final class DefaultImageAssetsProvider: ImageAssetsProvider, ImagesFolderPathRes assets[node] = makeAsset( for: node, setNode: setNode, - format: format, - preserveVectorData: preserveVectorData, - groupByFrame: groupByFrame, - namingStyle: namingStyle, + parameters: parameters, folderPath: folderPath ) } @@ -149,19 +145,13 @@ final class DefaultImageAssetsProvider: ImageAssetsProvider, ImagesFolderPathRes func saveImages( nodes: [ImageComponentSetRenderedNode], - format: ImageFormat, - preserveVectorData: Bool, - groupByFrame: Bool, - namingStyle: ImageNamingStyle, + parameters: ImagesParameters, in folderPath: String ) -> Promise<[ImageComponentSetAsset]> { perform(on: DispatchQueue.global(qos: .userInitiated)) { self.makeAssets( for: nodes, - format: format, - preserveVectorData: preserveVectorData, - groupByFrame: groupByFrame, - namingStyle: namingStyle, + parameters: parameters, folderPath: Path(folderPath) ) }.nest { assets in @@ -173,7 +163,7 @@ final class DefaultImageAssetsProvider: ImageAssetsProvider, ImagesFolderPathRes ) } }.then { assets in - try self.saveAssetFolders(assets: assets, groupByFrame: groupByFrame, in: folderPath) + try self.saveAssetFolders(assets: assets, groupByFrame: parameters.groupByFrame, in: folderPath) }.then { self.saveImageFiles(assets: assets) } diff --git a/Sources/FigmaGen/Providers/Images/Assets/ImageAssetsProvider.swift b/Sources/FigmaGen/Providers/Images/Assets/ImageAssetsProvider.swift index a309b7e..2eb7389 100644 --- a/Sources/FigmaGen/Providers/Images/Assets/ImageAssetsProvider.swift +++ b/Sources/FigmaGen/Providers/Images/Assets/ImageAssetsProvider.swift @@ -7,10 +7,7 @@ protocol ImageAssetsProvider { func saveImages( nodes: [ImageComponentSetRenderedNode], - format: ImageFormat, - preserveVectorData: Bool, - groupByFrame: Bool, - namingStyle: ImageNamingStyle, + parameters: ImagesParameters, in folderPath: String ) -> Promise<[ImageComponentSetAsset]> } diff --git a/Sources/FigmaGen/Providers/Images/DefaultImagesProvider.swift b/Sources/FigmaGen/Providers/Images/DefaultImagesProvider.swift index 451c3c1..bc0097c 100644 --- a/Sources/FigmaGen/Providers/Images/DefaultImagesProvider.swift +++ b/Sources/FigmaGen/Providers/Images/DefaultImagesProvider.swift @@ -149,19 +149,13 @@ final class DefaultImagesProvider: ImagesProvider { private func saveAssetImagesIfNeeded( nodes: [ImageComponentSetRenderedNode], - format: ImageFormat, - preserveVectorData: Bool, - groupByFrame: Bool, - namingStyle: ImageNamingStyle, + parameters: ImagesParameters, in assets: String? ) -> Promise<[ImageComponentSetAsset]> { assets.map { folderPath in imageAssetsProvider.saveImages( nodes: nodes, - format: format, - preserveVectorData: preserveVectorData, - groupByFrame: groupByFrame, - namingStyle: namingStyle, + parameters: parameters, in: folderPath ) } ?? .value([]) @@ -194,10 +188,7 @@ final class DefaultImagesProvider: ImagesProvider { when( fulfilled: self.saveAssetImagesIfNeeded( nodes: nodes, - format: parameters.format, - preserveVectorData: parameters.preserveVectorData, - groupByFrame: parameters.groupByFrame, - namingStyle: parameters.namingStyle, + parameters: parameters, in: parameters.assets ), self.saveResourceImagesIfNeeded(