From da71dd04520106e1cb9ca0df5c9aa4bf301ab32c Mon Sep 17 00:00:00 2001 From: "p.strelchenko" Date: Thu, 14 Dec 2023 21:39:57 +0600 Subject: [PATCH 01/11] =?UTF-8?q?[MOB-35468]=20=D0=92=D1=8B=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D0=B8=D1=82=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83?= =?UTF-8?q?=D1=80=D0=B0=D1=86=D0=B8=D1=8E=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=8B=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D1=83?= =?UTF-8?q?=D1=8E=D1=89=D0=B5=D0=B3=D0=BE=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/FigmaGen/Commands/TokensCommand.swift | 14 ++-- ...ltTokensGenerationParametersResolver.swift | 6 +- .../Configuration/Templates/Template.swift | 51 +++++++++++++ .../Templates/TemplateWrapper.swift | 22 ++++++ .../Tokens/TokensTemplateConfiguration.swift | 71 ------------------- 5 files changed, 83 insertions(+), 81 deletions(-) create mode 100644 Sources/FigmaGen/Models/Configuration/Templates/Template.swift create mode 100644 Sources/FigmaGen/Models/Configuration/Templates/TemplateWrapper.swift diff --git a/Sources/FigmaGen/Commands/TokensCommand.swift b/Sources/FigmaGen/Commands/TokensCommand.swift index 03cb874..953e9b7 100644 --- a/Sources/FigmaGen/Commands/TokensCommand.swift +++ b/Sources/FigmaGen/Commands/TokensCommand.swift @@ -231,49 +231,49 @@ extension TokensCommand { accessToken: resolveAccessTokenConfiguration(), templates: TokensTemplateConfiguration( colors: [ - TokensTemplateConfiguration.Template( + Template( template: colorsTemplate.value, templateOptions: resolveTemplateOptions(colorsTemplateOptions.value), destination: colorsDestination.value ) ], baseColors: [ - TokensTemplateConfiguration.Template( + Template( template: baseColorsTemplate.value, templateOptions: resolveTemplateOptions(baseColorsTemplateOptions.value), destination: baseColorsDestination.value ) ], fontFamilies: [ - TokensTemplateConfiguration.Template( + Template( template: fontFamiliesTemplate.value, templateOptions: resolveTemplateOptions(fontFamiliesTemplateOptions.value), destination: fontFamiliesDestination.value ) ], typographies: [ - TokensTemplateConfiguration.Template( + Template( template: typographiesTemplate.value, templateOptions: resolveTemplateOptions(typographiesTemplateOptions.value), destination: typographiesDestination.value ) ], boxShadows: [ - TokensTemplateConfiguration.Template( + Template( template: boxShadowsTemplate.value, templateOptions: resolveTemplateOptions(boxShadowsTemplateOptions.value), destination: boxShadowsDestination.value ) ], theme: [ - TokensTemplateConfiguration.Template( + Template( template: themeTemplate.value, templateOptions: resolveTemplateOptions(themeTemplateOptions.value), destination: themeDestination.value ) ], spacing: [ - TokensTemplateConfiguration.Template( + Template( template: spacingTemplate.value, templateOptions: resolveTemplateOptions(spacingTemplateOptions.value), destination: spacingDestination.value diff --git a/Sources/FigmaGen/Generators/Tokens/GenerationParametersResolver/DefaultTokensGenerationParametersResolver.swift b/Sources/FigmaGen/Generators/Tokens/GenerationParametersResolver/DefaultTokensGenerationParametersResolver.swift index e01a7d3..f1d229c 100644 --- a/Sources/FigmaGen/Generators/Tokens/GenerationParametersResolver/DefaultTokensGenerationParametersResolver.swift +++ b/Sources/FigmaGen/Generators/Tokens/GenerationParametersResolver/DefaultTokensGenerationParametersResolver.swift @@ -18,7 +18,7 @@ final class DefaultTokensGenerationParametersResolver: TokensGenerationParameter } private func resolveTemplateType( - template: TokensTemplateConfiguration.Template, + template: Template, nativeTemplateName: String ) -> RenderTemplateType { if let templatePath = template.template { @@ -28,7 +28,7 @@ final class DefaultTokensGenerationParametersResolver: TokensGenerationParameter return .native(name: nativeTemplateName) } - private func resolveDestination(template: TokensTemplateConfiguration.Template) -> RenderDestination { + private func resolveDestination(template: Template) -> RenderDestination { if let destinationPath = template.destination { return .file(path: destinationPath) } @@ -37,7 +37,7 @@ final class DefaultTokensGenerationParametersResolver: TokensGenerationParameter } private func resolveRenderParameters( - templates: [TokensTemplateConfiguration.Template]?, + templates: [Template]?, nativeTemplateName: String ) -> [RenderParameters]? { guard let templateConfigurations = templates else { diff --git a/Sources/FigmaGen/Models/Configuration/Templates/Template.swift b/Sources/FigmaGen/Models/Configuration/Templates/Template.swift new file mode 100644 index 0000000..e29402c --- /dev/null +++ b/Sources/FigmaGen/Models/Configuration/Templates/Template.swift @@ -0,0 +1,51 @@ +import Foundation + +struct Template { + + // MARK: - Instance Properties + + let template: String? + let templateOptions: [String: Any]? + let destination: String? + + // MARK: - Initializers + + init( + template: String?, + templateOptions: [String: Any]?, + destination: String? + ) { + self.template = template + self.templateOptions = templateOptions + self.destination = destination + } +} + +// MARK: - Decodable + +extension Template: Decodable { + + // MARK: - Nested Types + + private enum CodingKeys: String, CodingKey { + case template + case templateOptions + case destination + } + + // MARK: - Initializers + + init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.template = try container.decodeIfPresent(forKey: .template) + + self.templateOptions = try container + .decodeIfPresent([String: AnyCodable].self, forKey: .templateOptions)? + .mapValues { + $0.value + } + + self.destination = try container.decodeIfPresent(forKey: .destination) + } +} diff --git a/Sources/FigmaGen/Models/Configuration/Templates/TemplateWrapper.swift b/Sources/FigmaGen/Models/Configuration/Templates/TemplateWrapper.swift new file mode 100644 index 0000000..f4e78fe --- /dev/null +++ b/Sources/FigmaGen/Models/Configuration/Templates/TemplateWrapper.swift @@ -0,0 +1,22 @@ +import Foundation + +struct TemplateWrapper: Decodable { + + // MARK: - Instance Properties + + let templates: [Template]? + + // MARK: - Initializers + + init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + + if container.decodeNil() { + self.templates = nil + } else if let singleValue = try? container.decode(Template.self) { + self.templates = [singleValue] + } else { + self.templates = try container.decode([Template].self) + } + } +} diff --git a/Sources/FigmaGen/Models/Configuration/Tokens/TokensTemplateConfiguration.swift b/Sources/FigmaGen/Models/Configuration/Tokens/TokensTemplateConfiguration.swift index 161d242..f5a7048 100644 --- a/Sources/FigmaGen/Models/Configuration/Tokens/TokensTemplateConfiguration.swift +++ b/Sources/FigmaGen/Models/Configuration/Tokens/TokensTemplateConfiguration.swift @@ -3,29 +3,6 @@ import FigmaGenTools struct TokensTemplateConfiguration { - // MARK: - Nested Types - - struct Template { - - // MARK: - Instance Properties - - let template: String? - let templateOptions: [String: Any]? - let destination: String? - - // MARK: - Initializers - - init( - template: String?, - templateOptions: [String: Any]?, - destination: String? - ) { - self.template = template - self.templateOptions = templateOptions - self.destination = destination - } - } - // MARK: - Instance Properties let colors: [Template]? @@ -53,27 +30,6 @@ extension TokensTemplateConfiguration: Decodable { case spacing } - private struct TemplateWrapper: Decodable { - - // MARK: - Instance Properties - - let templates: [Template]? - - // MARK: - Initializers - - init(from decoder: Decoder) throws { - let container = try decoder.singleValueContainer() - - if container.decodeNil() { - self.templates = nil - } else if let singleValue = try? container.decode(Template.self) { - self.templates = [singleValue] - } else { - self.templates = try container.decode([Template].self) - } - } - } - // MARK: - Initializers init(from decoder: Decoder) throws { @@ -88,30 +44,3 @@ extension TokensTemplateConfiguration: Decodable { self.spacing = try container.decodeIfPresent(TemplateWrapper.self, forKey: .spacing)?.templates } } - -// MARK: - - -extension TokensTemplateConfiguration.Template: Decodable { - - // MARK: - Nested Types - - private enum CodingKeys: String, CodingKey { - case template - case templateOptions - case destination - } - - // MARK: - Initializers - - init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - - self.template = try container.decodeIfPresent(forKey: .template) - - self.templateOptions = try container - .decodeIfPresent([String: AnyCodable].self, forKey: .templateOptions)? - .mapValues { $0.value } - - self.destination = try container.decodeIfPresent(forKey: .destination) - } -} From 310c3554608cd6a527c8a014c06e2191309d39f4 Mon Sep 17 00:00:00 2001 From: "p.strelchenko" Date: Thu, 14 Dec 2023 21:41:15 +0600 Subject: [PATCH 02/11] =?UTF-8?q?[MOB-35468]=20=D0=9F=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B8=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D1=8B=D0=B2=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=20Template=20=D0=B2=20TemplateConfiguration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/FigmaGen/Commands/TokensCommand.swift | 14 +++++----- ...ltTokensGenerationParametersResolver.swift | 6 ++-- ...late.swift => TemplateConfiguration.swift} | 4 +-- ...ift => TemplateConfigurationWrapper.swift} | 8 +++--- .../Tokens/TokensTemplateConfiguration.swift | 28 +++++++++---------- 5 files changed, 30 insertions(+), 30 deletions(-) rename Sources/FigmaGen/Models/Configuration/Templates/{Template.swift => TemplateConfiguration.swift} (93%) rename Sources/FigmaGen/Models/Configuration/Templates/{TemplateWrapper.swift => TemplateConfigurationWrapper.swift} (66%) diff --git a/Sources/FigmaGen/Commands/TokensCommand.swift b/Sources/FigmaGen/Commands/TokensCommand.swift index 953e9b7..72fd130 100644 --- a/Sources/FigmaGen/Commands/TokensCommand.swift +++ b/Sources/FigmaGen/Commands/TokensCommand.swift @@ -231,49 +231,49 @@ extension TokensCommand { accessToken: resolveAccessTokenConfiguration(), templates: TokensTemplateConfiguration( colors: [ - Template( + TemplateConfiguration( template: colorsTemplate.value, templateOptions: resolveTemplateOptions(colorsTemplateOptions.value), destination: colorsDestination.value ) ], baseColors: [ - Template( + TemplateConfiguration( template: baseColorsTemplate.value, templateOptions: resolveTemplateOptions(baseColorsTemplateOptions.value), destination: baseColorsDestination.value ) ], fontFamilies: [ - Template( + TemplateConfiguration( template: fontFamiliesTemplate.value, templateOptions: resolveTemplateOptions(fontFamiliesTemplateOptions.value), destination: fontFamiliesDestination.value ) ], typographies: [ - Template( + TemplateConfiguration( template: typographiesTemplate.value, templateOptions: resolveTemplateOptions(typographiesTemplateOptions.value), destination: typographiesDestination.value ) ], boxShadows: [ - Template( + TemplateConfiguration( template: boxShadowsTemplate.value, templateOptions: resolveTemplateOptions(boxShadowsTemplateOptions.value), destination: boxShadowsDestination.value ) ], theme: [ - Template( + TemplateConfiguration( template: themeTemplate.value, templateOptions: resolveTemplateOptions(themeTemplateOptions.value), destination: themeDestination.value ) ], spacing: [ - Template( + TemplateConfiguration( template: spacingTemplate.value, templateOptions: resolveTemplateOptions(spacingTemplateOptions.value), destination: spacingDestination.value diff --git a/Sources/FigmaGen/Generators/Tokens/GenerationParametersResolver/DefaultTokensGenerationParametersResolver.swift b/Sources/FigmaGen/Generators/Tokens/GenerationParametersResolver/DefaultTokensGenerationParametersResolver.swift index f1d229c..ede292b 100644 --- a/Sources/FigmaGen/Generators/Tokens/GenerationParametersResolver/DefaultTokensGenerationParametersResolver.swift +++ b/Sources/FigmaGen/Generators/Tokens/GenerationParametersResolver/DefaultTokensGenerationParametersResolver.swift @@ -18,7 +18,7 @@ final class DefaultTokensGenerationParametersResolver: TokensGenerationParameter } private func resolveTemplateType( - template: Template, + template: TemplateConfiguration, nativeTemplateName: String ) -> RenderTemplateType { if let templatePath = template.template { @@ -28,7 +28,7 @@ final class DefaultTokensGenerationParametersResolver: TokensGenerationParameter return .native(name: nativeTemplateName) } - private func resolveDestination(template: Template) -> RenderDestination { + private func resolveDestination(template: TemplateConfiguration) -> RenderDestination { if let destinationPath = template.destination { return .file(path: destinationPath) } @@ -37,7 +37,7 @@ final class DefaultTokensGenerationParametersResolver: TokensGenerationParameter } private func resolveRenderParameters( - templates: [Template]?, + templates: [TemplateConfiguration]?, nativeTemplateName: String ) -> [RenderParameters]? { guard let templateConfigurations = templates else { diff --git a/Sources/FigmaGen/Models/Configuration/Templates/Template.swift b/Sources/FigmaGen/Models/Configuration/Templates/TemplateConfiguration.swift similarity index 93% rename from Sources/FigmaGen/Models/Configuration/Templates/Template.swift rename to Sources/FigmaGen/Models/Configuration/Templates/TemplateConfiguration.swift index e29402c..4ed3645 100644 --- a/Sources/FigmaGen/Models/Configuration/Templates/Template.swift +++ b/Sources/FigmaGen/Models/Configuration/Templates/TemplateConfiguration.swift @@ -1,6 +1,6 @@ import Foundation -struct Template { +struct TemplateConfiguration { // MARK: - Instance Properties @@ -23,7 +23,7 @@ struct Template { // MARK: - Decodable -extension Template: Decodable { +extension TemplateConfiguration: Decodable { // MARK: - Nested Types diff --git a/Sources/FigmaGen/Models/Configuration/Templates/TemplateWrapper.swift b/Sources/FigmaGen/Models/Configuration/Templates/TemplateConfigurationWrapper.swift similarity index 66% rename from Sources/FigmaGen/Models/Configuration/Templates/TemplateWrapper.swift rename to Sources/FigmaGen/Models/Configuration/Templates/TemplateConfigurationWrapper.swift index f4e78fe..aeb54f1 100644 --- a/Sources/FigmaGen/Models/Configuration/Templates/TemplateWrapper.swift +++ b/Sources/FigmaGen/Models/Configuration/Templates/TemplateConfigurationWrapper.swift @@ -1,10 +1,10 @@ import Foundation -struct TemplateWrapper: Decodable { +struct TemplateConfigurationWrapper: Decodable { // MARK: - Instance Properties - let templates: [Template]? + let templates: [TemplateConfiguration]? // MARK: - Initializers @@ -13,10 +13,10 @@ struct TemplateWrapper: Decodable { if container.decodeNil() { self.templates = nil - } else if let singleValue = try? container.decode(Template.self) { + } else if let singleValue = try? container.decode(TemplateConfiguration.self) { self.templates = [singleValue] } else { - self.templates = try container.decode([Template].self) + self.templates = try container.decode([TemplateConfiguration].self) } } } diff --git a/Sources/FigmaGen/Models/Configuration/Tokens/TokensTemplateConfiguration.swift b/Sources/FigmaGen/Models/Configuration/Tokens/TokensTemplateConfiguration.swift index f5a7048..63600b8 100644 --- a/Sources/FigmaGen/Models/Configuration/Tokens/TokensTemplateConfiguration.swift +++ b/Sources/FigmaGen/Models/Configuration/Tokens/TokensTemplateConfiguration.swift @@ -5,13 +5,13 @@ struct TokensTemplateConfiguration { // MARK: - Instance Properties - let colors: [Template]? - let baseColors: [Template]? - let fontFamilies: [Template]? - let typographies: [Template]? - let boxShadows: [Template]? - let theme: [Template]? - let spacing: [Template]? + let colors: [TemplateConfiguration]? + let baseColors: [TemplateConfiguration]? + let fontFamilies: [TemplateConfiguration]? + let typographies: [TemplateConfiguration]? + let boxShadows: [TemplateConfiguration]? + let theme: [TemplateConfiguration]? + let spacing: [TemplateConfiguration]? } // MARK: - Decodable @@ -35,12 +35,12 @@ extension TokensTemplateConfiguration: Decodable { init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) - self.colors = try container.decodeIfPresent(TemplateWrapper.self, forKey: .colors)?.templates - self.baseColors = try container.decodeIfPresent(TemplateWrapper.self, forKey: .baseColors)?.templates - self.fontFamilies = try container.decodeIfPresent(TemplateWrapper.self, forKey: .fontFamilies)?.templates - self.typographies = try container.decodeIfPresent(TemplateWrapper.self, forKey: .typographies)?.templates - self.boxShadows = try container.decodeIfPresent(TemplateWrapper.self, forKey: .boxShadows)?.templates - self.theme = try container.decodeIfPresent(TemplateWrapper.self, forKey: .theme)?.templates - self.spacing = try container.decodeIfPresent(TemplateWrapper.self, forKey: .spacing)?.templates + self.colors = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .colors)?.templates + self.baseColors = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .baseColors)?.templates + self.fontFamilies = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .fontFamilies)?.templates + self.typographies = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .typographies)?.templates + self.boxShadows = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .boxShadows)?.templates + self.theme = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .theme)?.templates + self.spacing = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .spacing)?.templates } } From f5254a406fc2e9e146968369d121c32248421521 Mon Sep 17 00:00:00 2001 From: "p.strelchenko" Date: Thu, 14 Dec 2023 21:45:28 +0600 Subject: [PATCH 03/11] =?UTF-8?q?[MOB-35468]=20=D0=94=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D1=8F=D0=B5=D1=82=20=D0=BA=D0=BB=D1=8E=D1=87=20tem?= =?UTF-8?q?plates=20=D0=B2=20=D0=BE=D0=B1=D1=89=D1=83=D1=8E=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0=D1=86=D0=B8=D1=8E=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=B0=D1=80=D1=81=D0=B8=D0=BD=D0=B3?= =?UTF-8?q?=D0=B0=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0=D1=86=D0=B8=D0=B9=20?= =?UTF-8?q?=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Configuration/GenerationConfiguration.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Sources/FigmaGen/Models/Configuration/GenerationConfiguration.swift b/Sources/FigmaGen/Models/Configuration/GenerationConfiguration.swift index 126e804..2f65498 100644 --- a/Sources/FigmaGen/Models/Configuration/GenerationConfiguration.swift +++ b/Sources/FigmaGen/Models/Configuration/GenerationConfiguration.swift @@ -8,6 +8,9 @@ struct GenerationConfiguration: Decodable { private enum CodingKeys: String, CodingKey { case file case accessToken + case templates + + // TODO [MOB-35468] Remove template, templateOptions, destination case template case templateOptions case destination @@ -17,6 +20,9 @@ struct GenerationConfiguration: Decodable { let file: FileConfiguration? let accessToken: AccessTokenConfiguration? + let templates: [TemplateConfiguration]? + + // TODO [MOB-35468] Remove template, templateOptions, destination let template: String? let templateOptions: [String: Any]? let destination: String? @@ -26,12 +32,17 @@ struct GenerationConfiguration: Decodable { init( file: FileConfiguration?, accessToken: AccessTokenConfiguration?, + templates: [TemplateConfiguration]?, + // TODO [MOB-35468] Remove template, templateOptions, destination template: String?, templateOptions: [String: Any]?, destination: String? ) { self.file = file self.accessToken = accessToken + self.templates = templates + + // TODO [MOB-35468] Remove template, templateOptions, destination self.template = template self.templateOptions = templateOptions self.destination = destination @@ -45,6 +56,9 @@ struct GenerationConfiguration: Decodable { let container = try decoder.container(keyedBy: CodingKeys.self) + templates = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .templates)?.templates + + // TODO [MOB-35468] Remove template, templateOptions, destination template = try container.decodeIfPresent(forKey: .template) templateOptions = try container @@ -64,6 +78,8 @@ struct GenerationConfiguration: Decodable { return Self( file: file ?? base.file, accessToken: accessToken ?? base.accessToken, + templates: templates, + // TODO [MOB-35468] Remove template, templateOptions, destination template: template, templateOptions: templateOptions, destination: destination From 178e537faf9fc036aba9ecc941840625d0866337 Mon Sep 17 00:00:00 2001 From: "p.strelchenko" Date: Thu, 14 Dec 2023 21:55:46 +0600 Subject: [PATCH 04/11] =?UTF-8?q?[MOB-35468]=20=D0=92=D1=8B=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D0=B8=D1=82=20=D0=BA=D0=BE=D0=BD=D0=B2=D0=B5=D1=80=D1=82?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8E=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3?= =?UTF-8?q?=D1=83=D1=80=D0=B0=D1=86=D0=B8=D0=B9=20=D1=88=D0=B0=D0=B1=D0=BB?= =?UTF-8?q?=D0=BE=D0=BD=D0=BE=D0=B2=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/FigmaGen/Dependencies.swift | 7 +- ...ltTokensGenerationParametersResolver.swift | 68 +++++-------------- .../DefaultRenderParametersResolver.swift | 51 ++++++++++++++ .../RenderParametersResolver.swift | 10 +++ 4 files changed, 83 insertions(+), 53 deletions(-) create mode 100644 Sources/FigmaGen/Resolvers/RenderParameters/DefaultRenderParametersResolver.swift create mode 100644 Sources/FigmaGen/Resolvers/RenderParameters/RenderParametersResolver.swift diff --git a/Sources/FigmaGen/Dependencies.swift b/Sources/FigmaGen/Dependencies.swift index 6786f0d..64843cb 100644 --- a/Sources/FigmaGen/Dependencies.swift +++ b/Sources/FigmaGen/Dependencies.swift @@ -64,9 +64,12 @@ enum Dependencies { // MARK: - static let tokensResolver: TokensResolver = DefaultTokensResolver() + static let renderParametersResolver: RenderParametersResolver = DefaultRenderParametersResolver() - static let tokensGenerationParametersResolver: TokensGenerationParametersResolver - = DefaultTokensGenerationParametersResolver() + static let tokensGenerationParametersResolver: TokensGenerationParametersResolver = + DefaultTokensGenerationParametersResolver( + renderParametersResolver: renderParametersResolver + ) static let colorTokensContextProvider: ColorTokensContextProvider = DefaultColorTokensContextProvider( tokensResolver: tokensResolver diff --git a/Sources/FigmaGen/Generators/Tokens/GenerationParametersResolver/DefaultTokensGenerationParametersResolver.swift b/Sources/FigmaGen/Generators/Tokens/GenerationParametersResolver/DefaultTokensGenerationParametersResolver.swift index ede292b..a3a1a4c 100644 --- a/Sources/FigmaGen/Generators/Tokens/GenerationParametersResolver/DefaultTokensGenerationParametersResolver.swift +++ b/Sources/FigmaGen/Generators/Tokens/GenerationParametersResolver/DefaultTokensGenerationParametersResolver.swift @@ -2,6 +2,16 @@ import Foundation final class DefaultTokensGenerationParametersResolver: TokensGenerationParametersResolver { + // MARK: - Instance Properties + + let renderParametersResolver: RenderParametersResolver + + // MARK: - Initializers + + init(renderParametersResolver: RenderParametersResolver) { + self.renderParametersResolver = renderParametersResolver + } + // MARK: - Instance Methods private func resolveAccessToken(configuration: TokensConfiguration) -> String? { @@ -17,50 +27,6 @@ final class DefaultTokensGenerationParametersResolver: TokensGenerationParameter } } - private func resolveTemplateType( - template: TemplateConfiguration, - nativeTemplateName: String - ) -> RenderTemplateType { - if let templatePath = template.template { - return .custom(path: templatePath) - } - - return .native(name: nativeTemplateName) - } - - private func resolveDestination(template: TemplateConfiguration) -> RenderDestination { - if let destinationPath = template.destination { - return .file(path: destinationPath) - } - - return .console - } - - private func resolveRenderParameters( - templates: [TemplateConfiguration]?, - nativeTemplateName: String - ) -> [RenderParameters]? { - guard let templateConfigurations = templates else { - return nil - } - - return templateConfigurations.map { template -> RenderParameters in - let templateType = resolveTemplateType( - template: template, - nativeTemplateName: nativeTemplateName - ) - - let destination = resolveDestination(template: template) - - let template = RenderTemplate( - type: templateType, - options: template.templateOptions ?? [:] - ) - - return RenderParameters(template: template, destination: destination) - } - } - // MARK: - // swiftlint:disable:next function_body_length @@ -79,37 +45,37 @@ final class DefaultTokensGenerationParametersResolver: TokensGenerationParameter accessToken: accessToken ) - let colorRenderParameters = resolveRenderParameters( + let colorRenderParameters = renderParametersResolver.resolveRenderParameters( templates: configuration.templates?.colors, nativeTemplateName: "ColorTokens" ) - let baseColorRenderParameters = resolveRenderParameters( + let baseColorRenderParameters = renderParametersResolver.resolveRenderParameters( templates: configuration.templates?.baseColors, nativeTemplateName: "BaseColorTokens" ) - let fontFamilyRenderParameters = resolveRenderParameters( + let fontFamilyRenderParameters = renderParametersResolver.resolveRenderParameters( templates: configuration.templates?.fontFamilies, nativeTemplateName: "FontFamilyTokens" ) - let typographyRenderParameters = resolveRenderParameters( + let typographyRenderParameters = renderParametersResolver.resolveRenderParameters( templates: configuration.templates?.typographies, nativeTemplateName: "TypographyTokens" ) - let boxShadowRenderParameters = resolveRenderParameters( + let boxShadowRenderParameters = renderParametersResolver.resolveRenderParameters( templates: configuration.templates?.boxShadows, nativeTemplateName: "BoxShadowTokens" ) - let themeRenderParameters = resolveRenderParameters( + let themeRenderParameters = renderParametersResolver.resolveRenderParameters( templates: configuration.templates?.theme, nativeTemplateName: "Theme" ) - let spacingRenderParameters = resolveRenderParameters( + let spacingRenderParameters = renderParametersResolver.resolveRenderParameters( templates: configuration.templates?.spacing, nativeTemplateName: "SpacingTokens" ) diff --git a/Sources/FigmaGen/Resolvers/RenderParameters/DefaultRenderParametersResolver.swift b/Sources/FigmaGen/Resolvers/RenderParameters/DefaultRenderParametersResolver.swift new file mode 100644 index 0000000..f7ad9b5 --- /dev/null +++ b/Sources/FigmaGen/Resolvers/RenderParameters/DefaultRenderParametersResolver.swift @@ -0,0 +1,51 @@ +import Foundation + +final class DefaultRenderParametersResolver: RenderParametersResolver { + + // MARK: - Instance Methods + + private func resolveTemplateType( + template: TemplateConfiguration, + nativeTemplateName: String + ) -> RenderTemplateType { + if let templatePath = template.template { + return .custom(path: templatePath) + } + + return .native(name: nativeTemplateName) + } + + private func resolveDestination(template: TemplateConfiguration) -> RenderDestination { + if let destinationPath = template.destination { + return .file(path: destinationPath) + } + + return .console + } + + func resolveRenderParameters( + templates: [TemplateConfiguration]?, + nativeTemplateName: String + ) -> [RenderParameters]? { + guard let templateConfigurations = templates else { + return nil + } + + return templateConfigurations.map { template -> RenderParameters in + let templateType = resolveTemplateType( + template: template, + nativeTemplateName: nativeTemplateName + ) + + let destination = resolveDestination(template: template) + + let template = RenderTemplate( + type: templateType, + options: template.templateOptions ?? [:] + ) + + return RenderParameters(template: template, destination: destination) + } + } + +} \ No newline at end of file diff --git a/Sources/FigmaGen/Resolvers/RenderParameters/RenderParametersResolver.swift b/Sources/FigmaGen/Resolvers/RenderParameters/RenderParametersResolver.swift new file mode 100644 index 0000000..bebfb1e --- /dev/null +++ b/Sources/FigmaGen/Resolvers/RenderParameters/RenderParametersResolver.swift @@ -0,0 +1,10 @@ +import Foundation + +protocol RenderParametersResolver { + + func resolveRenderParameters( + templates: [TemplateConfiguration]?, + nativeTemplateName: String + ) -> [RenderParameters]? + +} From 8d01d0d35d1d42f5d226e017acc1f08c79be84eb Mon Sep 17 00:00:00 2001 From: "p.strelchenko" Date: Thu, 14 Dec 2023 22:25:58 +0600 Subject: [PATCH 05/11] =?UTF-8?q?[MOB-35468]=20=D0=92=D1=8B=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D0=B8=D1=82=20=D0=BA=D0=BE=D0=BD=D0=B2=D0=B5=D1=80=D1=82?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8E=20AccessToken=20=D0=B2=20=D0=BE=D1=82?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0?= =?UTF-8?q?=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/FigmaGen/Dependencies.swift | 13 ++++++---- .../DefaultColorStylesGenerator.swift | 9 +++++-- .../GenerationParametersResolving.swift | 21 ++++++---------- .../Images/DefaultImagesGenerator.swift | 8 ++++++- .../DefaultShadowStylesGenerator.swift | 8 ++++++- .../DefaultTextStylesGenerator.swift | 9 +++++-- ...ltTokensGenerationParametersResolver.swift | 24 ++++++------------- .../AccessToken/AccessTokenResolver.swift | 7 ++++++ .../DefaultAccessTokenResolver.swift | 18 ++++++++++++++ 9 files changed, 76 insertions(+), 41 deletions(-) create mode 100644 Sources/FigmaGen/Resolvers/AccessToken/AccessTokenResolver.swift create mode 100644 Sources/FigmaGen/Resolvers/AccessToken/DefaultAccessTokenResolver.swift diff --git a/Sources/FigmaGen/Dependencies.swift b/Sources/FigmaGen/Dependencies.swift index 64843cb..94e5d82 100644 --- a/Sources/FigmaGen/Dependencies.swift +++ b/Sources/FigmaGen/Dependencies.swift @@ -65,6 +65,7 @@ enum Dependencies { static let tokensResolver: TokensResolver = DefaultTokensResolver() static let renderParametersResolver: RenderParametersResolver = DefaultRenderParametersResolver() + static let accessTokenResolver: AccessTokenResolver = DefaultAccessTokenResolver() static let tokensGenerationParametersResolver: TokensGenerationParametersResolver = DefaultTokensGenerationParametersResolver( @@ -111,22 +112,26 @@ enum Dependencies { static let colorStylesGenerator: ColorStylesGenerator = DefaultColorStylesGenerator( colorStylesProvider: colorStylesProvider, - templateRenderer: templateRenderer + templateRenderer: templateRenderer, + accessTokenResolver: accessTokenResolver ) static let textStylesGenerator: TextStylesGenerator = DefaultTextStylesGenerator( textStylesProvider: textStylesProvider, - templateRenderer: templateRenderer + templateRenderer: templateRenderer, + accessTokenResolver: accessTokenResolver ) static let imagesGenerator: ImagesGenerator = DefaultImagesGenerator( imagesProvider: imagesProvider, - templateRenderer: templateRenderer + templateRenderer: templateRenderer, + accessTokenResolver: accessTokenResolver ) static let shadowStylesGenerator: ShadowStylesGenerator = DefaultShadowStylesGenerator( shadowStylesProvider: shadowStylesProvider, - templateRenderer: templateRenderer + templateRenderer: templateRenderer, + accessTokenResolver: accessTokenResolver ) static let colorTokensGenerator: ColorTokensGenerator = DefaultColorTokensGenerator( diff --git a/Sources/FigmaGen/Generators/ColorStyles/DefaultColorStylesGenerator.swift b/Sources/FigmaGen/Generators/ColorStyles/DefaultColorStylesGenerator.swift index 9189248..a084b3a 100644 --- a/Sources/FigmaGen/Generators/ColorStyles/DefaultColorStylesGenerator.swift +++ b/Sources/FigmaGen/Generators/ColorStyles/DefaultColorStylesGenerator.swift @@ -8,15 +8,20 @@ final class DefaultColorStylesGenerator: ColorStylesGenerator, GenerationParamet let colorStylesProvider: ColorStylesProvider let templateRenderer: TemplateRenderer - + let accessTokenResolver: AccessTokenResolver let defaultTemplateType = RenderTemplateType.native(name: "ColorStyles") let defaultDestination = RenderDestination.console // MARK: - Initializers - init(colorStylesProvider: ColorStylesProvider, templateRenderer: TemplateRenderer) { + init( + colorStylesProvider: ColorStylesProvider, + templateRenderer: TemplateRenderer, + accessTokenResolver: AccessTokenResolver + ) { self.colorStylesProvider = colorStylesProvider self.templateRenderer = templateRenderer + self.accessTokenResolver = accessTokenResolver } // MARK: - Instance Methods diff --git a/Sources/FigmaGen/Generators/GenerationParametersResolving.swift b/Sources/FigmaGen/Generators/GenerationParametersResolving.swift index d7974e5..752c871 100644 --- a/Sources/FigmaGen/Generators/GenerationParametersResolving.swift +++ b/Sources/FigmaGen/Generators/GenerationParametersResolving.swift @@ -4,6 +4,10 @@ protocol GenerationParametersResolving { // MARK: - Instance Properties + let accessTokenResolver: AccessTokenResolver + + // MARK: - Instance Properties + var defaultTemplateType: RenderTemplateType { get } var defaultDestination: RenderDestination { get } @@ -16,19 +20,6 @@ extension GenerationParametersResolving { // MARK: - Instance Methods - private func resolveAccessToken(configuration: GenerationConfiguration) -> String? { - switch configuration.accessToken { - case let .value(accessToken): - return accessToken - - case let .environmentVariable(environmentVariable): - return ProcessInfo.processInfo.environment[environmentVariable] - - case nil: - return nil - } - } - private func resolveTemplateType(configuration: GenerationConfiguration) -> RenderTemplateType { if let templatePath = configuration.template { return .custom(path: templatePath) @@ -52,7 +43,9 @@ extension GenerationParametersResolving { throw GenerationParametersError.invalidFileConfiguration } - guard let accessToken = resolveAccessToken(configuration: configuration), !accessToken.isEmpty else { + guard let accessToken = accessTokenResolver.resolveAccessToken( + from: configuration.accessToken + ), !accessToken.isEmpty else { throw GenerationParametersError.invalidAccessToken } diff --git a/Sources/FigmaGen/Generators/Images/DefaultImagesGenerator.swift b/Sources/FigmaGen/Generators/Images/DefaultImagesGenerator.swift index ec8a4e2..7330a64 100644 --- a/Sources/FigmaGen/Generators/Images/DefaultImagesGenerator.swift +++ b/Sources/FigmaGen/Generators/Images/DefaultImagesGenerator.swift @@ -8,15 +8,21 @@ final class DefaultImagesGenerator: ImagesGenerator, GenerationParametersResolvi let imagesProvider: ImagesProvider let templateRenderer: TemplateRenderer + let accessTokenResolver: AccessTokenResolver let defaultTemplateType = RenderTemplateType.native(name: "Images") let defaultDestination = RenderDestination.console // MARK: - Initializers - init(imagesProvider: ImagesProvider, templateRenderer: TemplateRenderer) { + init( + imagesProvider: ImagesProvider, + templateRenderer: TemplateRenderer, + accessTokenResolver: AccessTokenResolver + ) { self.imagesProvider = imagesProvider self.templateRenderer = templateRenderer + self.accessTokenResolver = accessTokenResolver } // MARK: - Instance Methods diff --git a/Sources/FigmaGen/Generators/ShadowStyles/DefaultShadowStylesGenerator.swift b/Sources/FigmaGen/Generators/ShadowStyles/DefaultShadowStylesGenerator.swift index 18b9551..042c384 100644 --- a/Sources/FigmaGen/Generators/ShadowStyles/DefaultShadowStylesGenerator.swift +++ b/Sources/FigmaGen/Generators/ShadowStyles/DefaultShadowStylesGenerator.swift @@ -8,15 +8,21 @@ final class DefaultShadowStylesGenerator: ShadowStylesGenerator, GenerationParam let shadowStylesProvider: ShadowStylesProvider let templateRenderer: TemplateRenderer + let accessTokenResolver: AccessTokenResolver let defaultTemplateType: RenderTemplateType = .native(name: "ShadowStyles") let defaultDestination: RenderDestination = .console // MARK: - Initializers - init(shadowStylesProvider: ShadowStylesProvider, templateRenderer: TemplateRenderer) { + init( + shadowStylesProvider: ShadowStylesProvider, + templateRenderer: TemplateRenderer, + accessTokenResolver: AccessTokenResolver + ) { self.shadowStylesProvider = shadowStylesProvider self.templateRenderer = templateRenderer + self.accessTokenResolver = accessTokenResolver } // MARK: - Instance Methods diff --git a/Sources/FigmaGen/Generators/TextStyles/DefaultTextStylesGenerator.swift b/Sources/FigmaGen/Generators/TextStyles/DefaultTextStylesGenerator.swift index d3d4ca3..8bee228 100644 --- a/Sources/FigmaGen/Generators/TextStyles/DefaultTextStylesGenerator.swift +++ b/Sources/FigmaGen/Generators/TextStyles/DefaultTextStylesGenerator.swift @@ -8,15 +8,20 @@ final class DefaultTextStylesGenerator: TextStylesGenerator, GenerationParameter let textStylesProvider: TextStylesProvider let templateRenderer: TemplateRenderer - + let accessTokenResolver: AccessTokenResolver let defaultTemplateType = RenderTemplateType.native(name: "TextStyles") let defaultDestination = RenderDestination.console // MARK: - Initializers - init(textStylesProvider: TextStylesProvider, templateRenderer: TemplateRenderer) { + init( + textStylesProvider: TextStylesProvider, + templateRenderer: TemplateRenderer, + accessTokenResolver: AccessTokenResolver + ) { self.textStylesProvider = textStylesProvider self.templateRenderer = templateRenderer + self.accessTokenResolver = accessTokenResolver } // MARK: - Instance Methods diff --git a/Sources/FigmaGen/Generators/Tokens/GenerationParametersResolver/DefaultTokensGenerationParametersResolver.swift b/Sources/FigmaGen/Generators/Tokens/GenerationParametersResolver/DefaultTokensGenerationParametersResolver.swift index a3a1a4c..981e25f 100644 --- a/Sources/FigmaGen/Generators/Tokens/GenerationParametersResolver/DefaultTokensGenerationParametersResolver.swift +++ b/Sources/FigmaGen/Generators/Tokens/GenerationParametersResolver/DefaultTokensGenerationParametersResolver.swift @@ -5,26 +5,16 @@ final class DefaultTokensGenerationParametersResolver: TokensGenerationParameter // MARK: - Instance Properties let renderParametersResolver: RenderParametersResolver + let accessTokenResolver: AccessTokenResolver // MARK: - Initializers - init(renderParametersResolver: RenderParametersResolver) { + init( + renderParametersResolver: RenderParametersResolver, + accessTokenResolver: AccessTokenResolver + ) { self.renderParametersResolver = renderParametersResolver - } - - // MARK: - Instance Methods - - private func resolveAccessToken(configuration: TokensConfiguration) -> String? { - switch configuration.accessToken { - case let .value(accessToken): - return accessToken - - case let .environmentVariable(environmentVariable): - return ProcessInfo.processInfo.environment[environmentVariable] - - case nil: - return nil - } + self.accessTokenResolver = accessTokenResolver } // MARK: - @@ -35,7 +25,7 @@ final class DefaultTokensGenerationParametersResolver: TokensGenerationParameter throw GenerationParametersError.invalidFileConfiguration } - guard let accessToken = resolveAccessToken(configuration: configuration) else { + guard let accessToken = accessTokenResolver.resolveAccessToken(from: configuration.accessToken) else { throw GenerationParametersError.invalidAccessToken } diff --git a/Sources/FigmaGen/Resolvers/AccessToken/AccessTokenResolver.swift b/Sources/FigmaGen/Resolvers/AccessToken/AccessTokenResolver.swift new file mode 100644 index 0000000..d7de0ba --- /dev/null +++ b/Sources/FigmaGen/Resolvers/AccessToken/AccessTokenResolver.swift @@ -0,0 +1,7 @@ +import Foundation + +protocol AccessTokenResolver { + + func resolveAccessToken(from configuration: AccessTokenConfiguration?) -> String? + +} \ No newline at end of file diff --git a/Sources/FigmaGen/Resolvers/AccessToken/DefaultAccessTokenResolver.swift b/Sources/FigmaGen/Resolvers/AccessToken/DefaultAccessTokenResolver.swift new file mode 100644 index 0000000..daa7b74 --- /dev/null +++ b/Sources/FigmaGen/Resolvers/AccessToken/DefaultAccessTokenResolver.swift @@ -0,0 +1,18 @@ +import Foundation + +final class DefaultAccessTokenResolver : AccessTokenResolver { + + func resolveAccessToken(from configuration: AccessTokenConfiguration?) -> String? { + switch configuration { + case let .value(accessToken): + return accessToken + + case let .environmentVariable(environmentVariable): + return ProcessInfo.processInfo.environment[environmentVariable] + + case nil: + return nil + } + } + +} \ No newline at end of file From ea43a3354e15c624e2725c79399edb5f7612ece0 Mon Sep 17 00:00:00 2001 From: "p.strelchenko" Date: Thu, 14 Dec 2023 22:42:31 +0600 Subject: [PATCH 06/11] =?UTF-8?q?[MOB-35468]=20=D0=9E=D0=B1=D0=BE=D0=B1?= =?UTF-8?q?=D1=89=D0=B0=D0=B5=D1=82=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B?= =?UTF-8?q?=20RenderParametersResolver=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BE?= =?UTF-8?q?=D1=81=D0=BB=D0=B5=D0=B4=D1=83=D1=8E=D1=89=D0=B5=D0=B3=D0=BE=20?= =?UTF-8?q?=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ltTokensGenerationParametersResolver.swift | 14 ++++++------- .../DefaultRenderParametersResolver.swift | 21 ++++++++++++------- .../RenderParametersResolver.swift | 19 ++++++++++++++++- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/Sources/FigmaGen/Generators/Tokens/GenerationParametersResolver/DefaultTokensGenerationParametersResolver.swift b/Sources/FigmaGen/Generators/Tokens/GenerationParametersResolver/DefaultTokensGenerationParametersResolver.swift index 981e25f..9646f74 100644 --- a/Sources/FigmaGen/Generators/Tokens/GenerationParametersResolver/DefaultTokensGenerationParametersResolver.swift +++ b/Sources/FigmaGen/Generators/Tokens/GenerationParametersResolver/DefaultTokensGenerationParametersResolver.swift @@ -37,37 +37,37 @@ final class DefaultTokensGenerationParametersResolver: TokensGenerationParameter let colorRenderParameters = renderParametersResolver.resolveRenderParameters( templates: configuration.templates?.colors, - nativeTemplateName: "ColorTokens" + defaultTemplateType: .native(name: "ColorTokens") ) let baseColorRenderParameters = renderParametersResolver.resolveRenderParameters( templates: configuration.templates?.baseColors, - nativeTemplateName: "BaseColorTokens" + defaultTemplateType: .native(name: "BaseColorTokens") ) let fontFamilyRenderParameters = renderParametersResolver.resolveRenderParameters( templates: configuration.templates?.fontFamilies, - nativeTemplateName: "FontFamilyTokens" + defaultTemplateType: .native(name: "FontFamilyTokens") ) let typographyRenderParameters = renderParametersResolver.resolveRenderParameters( templates: configuration.templates?.typographies, - nativeTemplateName: "TypographyTokens" + defaultTemplateType: .native(name: "TypographyTokens") ) let boxShadowRenderParameters = renderParametersResolver.resolveRenderParameters( templates: configuration.templates?.boxShadows, - nativeTemplateName: "BoxShadowTokens" + defaultTemplateType: .native(name: "BoxShadowTokens") ) let themeRenderParameters = renderParametersResolver.resolveRenderParameters( templates: configuration.templates?.theme, - nativeTemplateName: "Theme" + defaultTemplateType: .native(name: "Theme") ) let spacingRenderParameters = renderParametersResolver.resolveRenderParameters( templates: configuration.templates?.spacing, - nativeTemplateName: "SpacingTokens" + defaultTemplateType: .native(name: "SpacingTokens") ) return TokensGenerationParameters( diff --git a/Sources/FigmaGen/Resolvers/RenderParameters/DefaultRenderParametersResolver.swift b/Sources/FigmaGen/Resolvers/RenderParameters/DefaultRenderParametersResolver.swift index f7ad9b5..daa441a 100644 --- a/Sources/FigmaGen/Resolvers/RenderParameters/DefaultRenderParametersResolver.swift +++ b/Sources/FigmaGen/Resolvers/RenderParameters/DefaultRenderParametersResolver.swift @@ -6,26 +6,30 @@ final class DefaultRenderParametersResolver: RenderParametersResolver { private func resolveTemplateType( template: TemplateConfiguration, - nativeTemplateName: String + defaultTemplateType: RenderTemplateType ) -> RenderTemplateType { if let templatePath = template.template { return .custom(path: templatePath) } - return .native(name: nativeTemplateName) + return defaultTemplateType } - private func resolveDestination(template: TemplateConfiguration) -> RenderDestination { + private func resolveDestination( + template: TemplateConfiguration, + defaultDestination: RenderDestination + ) -> RenderDestination { if let destinationPath = template.destination { return .file(path: destinationPath) } - return .console + return defaultDestination } func resolveRenderParameters( templates: [TemplateConfiguration]?, - nativeTemplateName: String + defaultTemplateType: RenderTemplateType, + defaultDestination: RenderDestination ) -> [RenderParameters]? { guard let templateConfigurations = templates else { return nil @@ -34,10 +38,13 @@ final class DefaultRenderParametersResolver: RenderParametersResolver { return templateConfigurations.map { template -> RenderParameters in let templateType = resolveTemplateType( template: template, - nativeTemplateName: nativeTemplateName + defaultTemplateType: defaultTemplateType ) - let destination = resolveDestination(template: template) + let destination = resolveDestination( + template: template, + defaultDestination: defaultDestination + ) let template = RenderTemplate( type: templateType, diff --git a/Sources/FigmaGen/Resolvers/RenderParameters/RenderParametersResolver.swift b/Sources/FigmaGen/Resolvers/RenderParameters/RenderParametersResolver.swift index bebfb1e..e1965ce 100644 --- a/Sources/FigmaGen/Resolvers/RenderParameters/RenderParametersResolver.swift +++ b/Sources/FigmaGen/Resolvers/RenderParameters/RenderParametersResolver.swift @@ -4,7 +4,24 @@ protocol RenderParametersResolver { func resolveRenderParameters( templates: [TemplateConfiguration]?, - nativeTemplateName: String + defaultTemplateType: RenderTemplateType, + defaultDestination: RenderDestination ) -> [RenderParameters]? } + +extension RenderParametersResolver { + + func resolveRenderParameters( + templates: [TemplateConfiguration]?, + defaultTemplateType: RenderTemplateType, + defaultDestination: RenderDestination = .console + ) -> [RenderParameters]? { + resolveRenderParameters( + templates: templates, + defaultTemplateType: defaultTemplateType, + defaultDestination: defaultDestination + ) + } + +} \ No newline at end of file From 156fa41669881a9aa51153f993de38511f2482ea Mon Sep 17 00:00:00 2001 From: "p.strelchenko" Date: Thu, 14 Dec 2023 22:48:08 +0600 Subject: [PATCH 07/11] =?UTF-8?q?[MOB-35468]=20=D0=94=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D1=8F=D0=B5=D1=82=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE?= =?UTF-8?q?=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=B3=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D1=80=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20=D0=BC=D0=BD?= =?UTF-8?q?=D0=BE=D0=B6=D0=B5=D1=81=D1=82=D0=B2=D0=BE=20=D1=84=D0=B0=D0=B9?= =?UTF-8?q?=D0=BB=D0=BE=D0=B2=20=D0=B8=D0=B7=20=D0=BE=D0=B4=D0=BD=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D1=82=D0=B8=D0=BF=D0=B0=20=D1=82=D0=BE=D0=BA?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=D0=B2=20=D1=82=D0=B5=D0=BD=D0=B5=D0=B9,=20?= =?UTF-8?q?=D1=86=D0=B2=D0=B5=D1=82=D0=BE=D0=B2,=20=D0=BA=D0=B0=D1=80?= =?UTF-8?q?=D1=82=D0=B8=D0=BD=D0=BE=D0=BA,=20=D1=81=D1=82=D0=B8=D0=BB?= =?UTF-8?q?=D0=B5=D0=B9=20=D1=82=D0=B5=D0=BA=D1=81=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/FigmaGen/Dependencies.swift | 12 ++++-- .../DefaultColorStylesGenerator.swift | 22 +++++++---- .../GenerationParametersResolving.swift | 37 +++++-------------- .../Images/DefaultImagesGenerator.swift | 19 +++++++--- .../DefaultShadowStylesGenerator.swift | 19 +++++++--- .../DefaultTextStylesGenerator.swift | 20 +++++++--- .../Parameters/GenerationParameters.swift | 2 +- 7 files changed, 74 insertions(+), 57 deletions(-) diff --git a/Sources/FigmaGen/Dependencies.swift b/Sources/FigmaGen/Dependencies.swift index 94e5d82..67fc1b9 100644 --- a/Sources/FigmaGen/Dependencies.swift +++ b/Sources/FigmaGen/Dependencies.swift @@ -113,25 +113,29 @@ enum Dependencies { static let colorStylesGenerator: ColorStylesGenerator = DefaultColorStylesGenerator( colorStylesProvider: colorStylesProvider, templateRenderer: templateRenderer, - accessTokenResolver: accessTokenResolver + accessTokenResolver: accessTokenResolver, + renderParametersResolver: renderParametersResolver ) static let textStylesGenerator: TextStylesGenerator = DefaultTextStylesGenerator( textStylesProvider: textStylesProvider, templateRenderer: templateRenderer, - accessTokenResolver: accessTokenResolver + accessTokenResolver: accessTokenResolver, + renderParametersResolver: renderParametersResolver ) static let imagesGenerator: ImagesGenerator = DefaultImagesGenerator( imagesProvider: imagesProvider, templateRenderer: templateRenderer, - accessTokenResolver: accessTokenResolver + accessTokenResolver: accessTokenResolver, + renderParametersResolver: renderParametersResolver ) static let shadowStylesGenerator: ShadowStylesGenerator = DefaultShadowStylesGenerator( shadowStylesProvider: shadowStylesProvider, templateRenderer: templateRenderer, - accessTokenResolver: accessTokenResolver + accessTokenResolver: accessTokenResolver, + renderParametersResolver: renderParametersResolver ) static let colorTokensGenerator: ColorTokensGenerator = DefaultColorTokensGenerator( diff --git a/Sources/FigmaGen/Generators/ColorStyles/DefaultColorStylesGenerator.swift b/Sources/FigmaGen/Generators/ColorStyles/DefaultColorStylesGenerator.swift index a084b3a..4f833ac 100644 --- a/Sources/FigmaGen/Generators/ColorStyles/DefaultColorStylesGenerator.swift +++ b/Sources/FigmaGen/Generators/ColorStyles/DefaultColorStylesGenerator.swift @@ -9,6 +9,8 @@ final class DefaultColorStylesGenerator: ColorStylesGenerator, GenerationParamet let colorStylesProvider: ColorStylesProvider let templateRenderer: TemplateRenderer let accessTokenResolver: AccessTokenResolver + let renderParametersResolver: RenderParametersResolver + let defaultTemplateType = RenderTemplateType.native(name: "ColorStyles") let defaultDestination = RenderDestination.console @@ -17,18 +19,20 @@ final class DefaultColorStylesGenerator: ColorStylesGenerator, GenerationParamet init( colorStylesProvider: ColorStylesProvider, templateRenderer: TemplateRenderer, - accessTokenResolver: AccessTokenResolver + accessTokenResolver: AccessTokenResolver, + renderParametersResolver: RenderParametersResolver ) { self.colorStylesProvider = colorStylesProvider self.templateRenderer = templateRenderer self.accessTokenResolver = accessTokenResolver + self.renderParametersResolver = renderParametersResolver } // MARK: - Instance Methods private func generate(parameters: GenerationParameters, assets: String?) -> Promise { firstly { - self.colorStylesProvider.fetchColorStyles( + colorStylesProvider.fetchColorStyles( from: parameters.file, nodes: parameters.nodes, assets: assets @@ -36,11 +40,15 @@ final class DefaultColorStylesGenerator: ColorStylesGenerator, GenerationParamet }.map { colorStyles in ColorStylesContext(colorStyles: colorStyles) }.done { context in - try self.templateRenderer.renderTemplate( - parameters.render.template, - to: parameters.render.destination, - context: context - ) + if let renderParametersList = parameters.renderParameters { + for params in renderParametersList { + try self.templateRenderer.renderTemplate( + params.template, + to: params.destination, + context: context + ) + } + } } } diff --git a/Sources/FigmaGen/Generators/GenerationParametersResolving.swift b/Sources/FigmaGen/Generators/GenerationParametersResolving.swift index 752c871..635e05a 100644 --- a/Sources/FigmaGen/Generators/GenerationParametersResolving.swift +++ b/Sources/FigmaGen/Generators/GenerationParametersResolving.swift @@ -5,6 +5,7 @@ protocol GenerationParametersResolving { // MARK: - Instance Properties let accessTokenResolver: AccessTokenResolver + let renderParametersResolver: RenderParametersResolver // MARK: - Instance Properties @@ -18,24 +19,6 @@ protocol GenerationParametersResolving { extension GenerationParametersResolving { - // MARK: - Instance Methods - - private func resolveTemplateType(configuration: GenerationConfiguration) -> RenderTemplateType { - if let templatePath = configuration.template { - return .custom(path: templatePath) - } - - return defaultTemplateType - } - - private func resolveDestination(configuration: GenerationConfiguration) -> RenderDestination { - if let destinationPath = configuration.destination { - return .file(path: destinationPath) - } - - return defaultDestination - } - // MARK: - func resolveGenerationParameters(from configuration: GenerationConfiguration) throws -> GenerationParameters { @@ -60,16 +43,16 @@ extension GenerationParametersResolving { excludedIDs: fileConfiguration.excludedNodes ) - let templateType = resolveTemplateType(configuration: configuration) - let destination = resolveDestination(configuration: configuration) - - let template = RenderTemplate( - type: templateType, - options: configuration.templateOptions ?? [:] + let renderParametersList = renderParametersResolver.resolveRenderParameters( + templates: configuration.templates, + defaultTemplateType: defaultTemplateType, + defaultDestination: defaultDestination ) - let render = RenderParameters(template: template, destination: destination) - - return GenerationParameters(file: file, nodes: nodes, render: render) + return GenerationParameters( + file: file, + nodes: nodes, + renderParameters: renderParametersList + ) } } diff --git a/Sources/FigmaGen/Generators/Images/DefaultImagesGenerator.swift b/Sources/FigmaGen/Generators/Images/DefaultImagesGenerator.swift index 7330a64..18879aa 100644 --- a/Sources/FigmaGen/Generators/Images/DefaultImagesGenerator.swift +++ b/Sources/FigmaGen/Generators/Images/DefaultImagesGenerator.swift @@ -9,6 +9,7 @@ final class DefaultImagesGenerator: ImagesGenerator, GenerationParametersResolvi let imagesProvider: ImagesProvider let templateRenderer: TemplateRenderer let accessTokenResolver: AccessTokenResolver + let renderParametersResolver: RenderParametersResolver let defaultTemplateType = RenderTemplateType.native(name: "Images") let defaultDestination = RenderDestination.console @@ -18,11 +19,13 @@ final class DefaultImagesGenerator: ImagesGenerator, GenerationParametersResolvi init( imagesProvider: ImagesProvider, templateRenderer: TemplateRenderer, - accessTokenResolver: AccessTokenResolver + accessTokenResolver: AccessTokenResolver, + renderParametersResolver: RenderParametersResolver ) { self.imagesProvider = imagesProvider self.templateRenderer = templateRenderer self.accessTokenResolver = accessTokenResolver + self.renderParametersResolver = renderParametersResolver } // MARK: - Instance Methods @@ -39,11 +42,15 @@ final class DefaultImagesGenerator: ImagesGenerator, GenerationParametersResolvi imageSets: imageSets.sorted { $0.name.lowercased() < $1.name.lowercased() } ) }.done { context in - try self.templateRenderer.renderTemplate( - parameters.render.template, - to: parameters.render.destination, - context: context - ) + if let renderParametersList = parameters.renderParameters { + for params in renderParametersList { + try self.templateRenderer.renderTemplate( + params.template, + to: params.destination, + context: context + ) + } + } } } diff --git a/Sources/FigmaGen/Generators/ShadowStyles/DefaultShadowStylesGenerator.swift b/Sources/FigmaGen/Generators/ShadowStyles/DefaultShadowStylesGenerator.swift index 042c384..ec46b46 100644 --- a/Sources/FigmaGen/Generators/ShadowStyles/DefaultShadowStylesGenerator.swift +++ b/Sources/FigmaGen/Generators/ShadowStyles/DefaultShadowStylesGenerator.swift @@ -9,6 +9,7 @@ final class DefaultShadowStylesGenerator: ShadowStylesGenerator, GenerationParam let shadowStylesProvider: ShadowStylesProvider let templateRenderer: TemplateRenderer let accessTokenResolver: AccessTokenResolver + let renderParametersResolver: RenderParametersResolver let defaultTemplateType: RenderTemplateType = .native(name: "ShadowStyles") let defaultDestination: RenderDestination = .console @@ -18,11 +19,13 @@ final class DefaultShadowStylesGenerator: ShadowStylesGenerator, GenerationParam init( shadowStylesProvider: ShadowStylesProvider, templateRenderer: TemplateRenderer, - accessTokenResolver: AccessTokenResolver + accessTokenResolver: AccessTokenResolver, + renderParametersResolver: RenderParametersResolver ) { self.shadowStylesProvider = shadowStylesProvider self.templateRenderer = templateRenderer self.accessTokenResolver = accessTokenResolver + self.renderParametersResolver = renderParametersResolver } // MARK: - Instance Methods @@ -33,11 +36,15 @@ final class DefaultShadowStylesGenerator: ShadowStylesGenerator, GenerationParam }.map { shadowStyles in ShadowStylesContext(shadowStyles: shadowStyles) }.done { context in - try self.templateRenderer.renderTemplate( - parameters.render.template, - to: parameters.render.destination, - context: context - ) + if let renderParametersList = parameters.renderParameters { + for params in renderParametersList { + try self.templateRenderer.renderTemplate( + params.template, + to: params.destination, + context: context + ) + } + } } } diff --git a/Sources/FigmaGen/Generators/TextStyles/DefaultTextStylesGenerator.swift b/Sources/FigmaGen/Generators/TextStyles/DefaultTextStylesGenerator.swift index 8bee228..3e5e272 100644 --- a/Sources/FigmaGen/Generators/TextStyles/DefaultTextStylesGenerator.swift +++ b/Sources/FigmaGen/Generators/TextStyles/DefaultTextStylesGenerator.swift @@ -9,6 +9,8 @@ final class DefaultTextStylesGenerator: TextStylesGenerator, GenerationParameter let textStylesProvider: TextStylesProvider let templateRenderer: TemplateRenderer let accessTokenResolver: AccessTokenResolver + let renderParametersResolver: RenderParametersResolver + let defaultTemplateType = RenderTemplateType.native(name: "TextStyles") let defaultDestination = RenderDestination.console @@ -17,11 +19,13 @@ final class DefaultTextStylesGenerator: TextStylesGenerator, GenerationParameter init( textStylesProvider: TextStylesProvider, templateRenderer: TemplateRenderer, - accessTokenResolver: AccessTokenResolver + accessTokenResolver: AccessTokenResolver, + renderParametersResolver: RenderParametersResolver ) { self.textStylesProvider = textStylesProvider self.templateRenderer = templateRenderer self.accessTokenResolver = accessTokenResolver + self.renderParametersResolver = renderParametersResolver } // MARK: - Instance Methods @@ -32,11 +36,15 @@ final class DefaultTextStylesGenerator: TextStylesGenerator, GenerationParameter }.map { textStyles in TextStylesContext(textStyles: textStyles) }.done { context in - try self.templateRenderer.renderTemplate( - parameters.render.template, - to: parameters.render.destination, - context: context - ) + if let renderParametersList = parameters.renderParameters { + for params in renderParametersList { + try self.templateRenderer.renderTemplate( + params.template, + to: params.destination, + context: context + ) + } + } } } diff --git a/Sources/FigmaGen/Models/Parameters/GenerationParameters.swift b/Sources/FigmaGen/Models/Parameters/GenerationParameters.swift index 624b681..005d6b9 100644 --- a/Sources/FigmaGen/Models/Parameters/GenerationParameters.swift +++ b/Sources/FigmaGen/Models/Parameters/GenerationParameters.swift @@ -6,5 +6,5 @@ struct GenerationParameters { let file: FileParameters let nodes: NodesParameters - let render: RenderParameters + let renderParameters: [RenderParameters]? } From cdaa8fac27bed1a7de4cfbef48cbdeb4ef4f5c27 Mon Sep 17 00:00:00 2001 From: "p.strelchenko" Date: Thu, 14 Dec 2023 23:10:34 +0600 Subject: [PATCH 08/11] =?UTF-8?q?[MOB-35468]=20=D0=98=D1=81=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D1=8F=D0=B5=D1=82=20=D0=BA=D0=BE=D0=BC=D0=BF?= =?UTF-8?q?=D0=B8=D0=BB=D1=8F=D1=86=D0=B8=D1=8E=20=D0=BF=D1=80=D0=BE=D0=B5?= =?UTF-8?q?=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FigmaGen/Commands/GenerationConfigurableCommand.swift | 7 +++++++ Sources/FigmaGen/Dependencies.swift | 3 ++- .../Generators/GenerationParametersResolving.swift | 4 ++-- .../Configuration/Templates/TemplateConfiguration.swift | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Sources/FigmaGen/Commands/GenerationConfigurableCommand.swift b/Sources/FigmaGen/Commands/GenerationConfigurableCommand.swift index 57f1a70..4aadbd2 100644 --- a/Sources/FigmaGen/Commands/GenerationConfigurableCommand.swift +++ b/Sources/FigmaGen/Commands/GenerationConfigurableCommand.swift @@ -27,6 +27,13 @@ extension GenerationConfigurableCommand { GenerationConfiguration( file: resolveFileConfiguration(), accessToken: resolveAccessTokenConfiguration(), + templates: [ + TemplateConfiguration( + template: template.value, + templateOptions: resolveTemplateOptions(), + destination: destination.value + ) + ], template: template.value, templateOptions: resolveTemplateOptions(), destination: destination.value diff --git a/Sources/FigmaGen/Dependencies.swift b/Sources/FigmaGen/Dependencies.swift index 67fc1b9..b75800f 100644 --- a/Sources/FigmaGen/Dependencies.swift +++ b/Sources/FigmaGen/Dependencies.swift @@ -69,7 +69,8 @@ enum Dependencies { static let tokensGenerationParametersResolver: TokensGenerationParametersResolver = DefaultTokensGenerationParametersResolver( - renderParametersResolver: renderParametersResolver + renderParametersResolver: renderParametersResolver, + accessTokenResolver: accessTokenResolver ) static let colorTokensContextProvider: ColorTokensContextProvider = DefaultColorTokensContextProvider( diff --git a/Sources/FigmaGen/Generators/GenerationParametersResolving.swift b/Sources/FigmaGen/Generators/GenerationParametersResolving.swift index 635e05a..c1382df 100644 --- a/Sources/FigmaGen/Generators/GenerationParametersResolving.swift +++ b/Sources/FigmaGen/Generators/GenerationParametersResolving.swift @@ -4,8 +4,8 @@ protocol GenerationParametersResolving { // MARK: - Instance Properties - let accessTokenResolver: AccessTokenResolver - let renderParametersResolver: RenderParametersResolver + var accessTokenResolver: AccessTokenResolver { get } + var renderParametersResolver: RenderParametersResolver { get } // MARK: - Instance Properties diff --git a/Sources/FigmaGen/Models/Configuration/Templates/TemplateConfiguration.swift b/Sources/FigmaGen/Models/Configuration/Templates/TemplateConfiguration.swift index 4ed3645..6ccede3 100644 --- a/Sources/FigmaGen/Models/Configuration/Templates/TemplateConfiguration.swift +++ b/Sources/FigmaGen/Models/Configuration/Templates/TemplateConfiguration.swift @@ -1,4 +1,5 @@ import Foundation +import FigmaGenTools struct TemplateConfiguration { From b55b34fee828dd7848afae561c4da39be6f05f05 Mon Sep 17 00:00:00 2001 From: "p.strelchenko" Date: Thu, 14 Dec 2023 23:18:23 +0600 Subject: [PATCH 09/11] =?UTF-8?q?[MOB-35468]=20=D0=A3=D0=B1=D0=B8=D1=80?= =?UTF-8?q?=D0=B0=D0=B5=D1=82=20=D0=BB=D0=B8=D1=88=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=D1=8B=20=D0=B8?= =?UTF-8?q?=D0=B7=20=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=D1=8B=20=D0=B3?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GenerationConfigurableCommand.swift | 7 ++-- .../GenerationConfiguration.swift | 36 ++----------------- 2 files changed, 5 insertions(+), 38 deletions(-) diff --git a/Sources/FigmaGen/Commands/GenerationConfigurableCommand.swift b/Sources/FigmaGen/Commands/GenerationConfigurableCommand.swift index 4aadbd2..ba0eb43 100644 --- a/Sources/FigmaGen/Commands/GenerationConfigurableCommand.swift +++ b/Sources/FigmaGen/Commands/GenerationConfigurableCommand.swift @@ -23,6 +23,8 @@ extension GenerationConfigurableCommand { // MARK: - Instance Properties + // !!! Important note !!! + // For CLI usage of FigmaGen we don't support multiple templates for any token type. var generationConfiguration: GenerationConfiguration { GenerationConfiguration( file: resolveFileConfiguration(), @@ -33,10 +35,7 @@ extension GenerationConfigurableCommand { templateOptions: resolveTemplateOptions(), destination: destination.value ) - ], - template: template.value, - templateOptions: resolveTemplateOptions(), - destination: destination.value + ] ) } diff --git a/Sources/FigmaGen/Models/Configuration/GenerationConfiguration.swift b/Sources/FigmaGen/Models/Configuration/GenerationConfiguration.swift index 2f65498..6be0f9f 100644 --- a/Sources/FigmaGen/Models/Configuration/GenerationConfiguration.swift +++ b/Sources/FigmaGen/Models/Configuration/GenerationConfiguration.swift @@ -9,11 +9,6 @@ struct GenerationConfiguration: Decodable { case file case accessToken case templates - - // TODO [MOB-35468] Remove template, templateOptions, destination - case template - case templateOptions - case destination } // MARK: - Instance Properties @@ -22,30 +17,16 @@ struct GenerationConfiguration: Decodable { let accessToken: AccessTokenConfiguration? let templates: [TemplateConfiguration]? - // TODO [MOB-35468] Remove template, templateOptions, destination - let template: String? - let templateOptions: [String: Any]? - let destination: String? - // MARK: - Initializers init( file: FileConfiguration?, accessToken: AccessTokenConfiguration?, - templates: [TemplateConfiguration]?, - // TODO [MOB-35468] Remove template, templateOptions, destination - template: String?, - templateOptions: [String: Any]?, - destination: String? + templates: [TemplateConfiguration]? ) { self.file = file self.accessToken = accessToken self.templates = templates - - // TODO [MOB-35468] Remove template, templateOptions, destination - self.template = template - self.templateOptions = templateOptions - self.destination = destination } init(from decoder: Decoder) throws { @@ -57,15 +38,6 @@ struct GenerationConfiguration: Decodable { let container = try decoder.container(keyedBy: CodingKeys.self) templates = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .templates)?.templates - - // TODO [MOB-35468] Remove template, templateOptions, destination - template = try container.decodeIfPresent(forKey: .template) - - templateOptions = try container - .decodeIfPresent([String: AnyCodable].self, forKey: .templateOptions)? - .mapValues { $0.value } - - destination = try container.decodeIfPresent(forKey: .destination) } // MARK: - Instance Methods @@ -78,11 +50,7 @@ struct GenerationConfiguration: Decodable { return Self( file: file ?? base.file, accessToken: accessToken ?? base.accessToken, - templates: templates, - // TODO [MOB-35468] Remove template, templateOptions, destination - template: template, - templateOptions: templateOptions, - destination: destination + templates: templates ) } } From 5cc6ed1e71663351d4d89f45501a55847b5b17b6 Mon Sep 17 00:00:00 2001 From: "p.strelchenko" Date: Fri, 15 Dec 2023 01:52:26 +0600 Subject: [PATCH 10/11] =?UTF-8?q?[MOB-35468]=20=D0=98=D1=81=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D1=8F=D0=B5=D1=82=20=D0=B7=D0=B0=D0=BC=D0=B5?= =?UTF-8?q?=D1=87=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BB=D0=B8=D0=BD=D1=82=D0=B5?= =?UTF-8?q?=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Templates/TemplateConfiguration.swift | 4 +--- .../Tokens/TokensTemplateConfiguration.swift | 20 ++++++++++++------- .../AccessToken/AccessTokenResolver.swift | 3 +-- .../DefaultAccessTokenResolver.swift | 5 ++--- .../DefaultRenderParametersResolver.swift | 3 +-- .../RenderParametersResolver.swift | 4 +--- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Sources/FigmaGen/Models/Configuration/Templates/TemplateConfiguration.swift b/Sources/FigmaGen/Models/Configuration/Templates/TemplateConfiguration.swift index 6ccede3..1e0a454 100644 --- a/Sources/FigmaGen/Models/Configuration/Templates/TemplateConfiguration.swift +++ b/Sources/FigmaGen/Models/Configuration/Templates/TemplateConfiguration.swift @@ -43,9 +43,7 @@ extension TemplateConfiguration: Decodable { self.templateOptions = try container .decodeIfPresent([String: AnyCodable].self, forKey: .templateOptions)? - .mapValues { - $0.value - } + .mapValues { $0.value } self.destination = try container.decodeIfPresent(forKey: .destination) } diff --git a/Sources/FigmaGen/Models/Configuration/Tokens/TokensTemplateConfiguration.swift b/Sources/FigmaGen/Models/Configuration/Tokens/TokensTemplateConfiguration.swift index 63600b8..a267946 100644 --- a/Sources/FigmaGen/Models/Configuration/Tokens/TokensTemplateConfiguration.swift +++ b/Sources/FigmaGen/Models/Configuration/Tokens/TokensTemplateConfiguration.swift @@ -35,12 +35,18 @@ extension TokensTemplateConfiguration: Decodable { init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) - self.colors = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .colors)?.templates - self.baseColors = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .baseColors)?.templates - self.fontFamilies = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .fontFamilies)?.templates - self.typographies = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .typographies)?.templates - self.boxShadows = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .boxShadows)?.templates - self.theme = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .theme)?.templates - self.spacing = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .spacing)?.templates + colors = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .colors)?.templates + baseColors = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .baseColors)?.templates + fontFamilies = try container.decodeIfPresent( + TemplateConfigurationWrapper.self, + forKey: .fontFamilies + )?.templates + typographies = try container.decodeIfPresent( + TemplateConfigurationWrapper.self, + forKey: .typographies + )?.templates + boxShadows = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .boxShadows)?.templates + theme = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .theme)?.templates + spacing = try container.decodeIfPresent(TemplateConfigurationWrapper.self, forKey: .spacing)?.templates } } diff --git a/Sources/FigmaGen/Resolvers/AccessToken/AccessTokenResolver.swift b/Sources/FigmaGen/Resolvers/AccessToken/AccessTokenResolver.swift index d7de0ba..2a7a71b 100644 --- a/Sources/FigmaGen/Resolvers/AccessToken/AccessTokenResolver.swift +++ b/Sources/FigmaGen/Resolvers/AccessToken/AccessTokenResolver.swift @@ -3,5 +3,4 @@ import Foundation protocol AccessTokenResolver { func resolveAccessToken(from configuration: AccessTokenConfiguration?) -> String? - -} \ No newline at end of file +} diff --git a/Sources/FigmaGen/Resolvers/AccessToken/DefaultAccessTokenResolver.swift b/Sources/FigmaGen/Resolvers/AccessToken/DefaultAccessTokenResolver.swift index daa7b74..9b167ab 100644 --- a/Sources/FigmaGen/Resolvers/AccessToken/DefaultAccessTokenResolver.swift +++ b/Sources/FigmaGen/Resolvers/AccessToken/DefaultAccessTokenResolver.swift @@ -1,6 +1,6 @@ import Foundation -final class DefaultAccessTokenResolver : AccessTokenResolver { +final class DefaultAccessTokenResolver: AccessTokenResolver { func resolveAccessToken(from configuration: AccessTokenConfiguration?) -> String? { switch configuration { @@ -14,5 +14,4 @@ final class DefaultAccessTokenResolver : AccessTokenResolver { return nil } } - -} \ No newline at end of file +} diff --git a/Sources/FigmaGen/Resolvers/RenderParameters/DefaultRenderParametersResolver.swift b/Sources/FigmaGen/Resolvers/RenderParameters/DefaultRenderParametersResolver.swift index daa441a..70fd9c9 100644 --- a/Sources/FigmaGen/Resolvers/RenderParameters/DefaultRenderParametersResolver.swift +++ b/Sources/FigmaGen/Resolvers/RenderParameters/DefaultRenderParametersResolver.swift @@ -54,5 +54,4 @@ final class DefaultRenderParametersResolver: RenderParametersResolver { return RenderParameters(template: template, destination: destination) } } - -} \ No newline at end of file +} diff --git a/Sources/FigmaGen/Resolvers/RenderParameters/RenderParametersResolver.swift b/Sources/FigmaGen/Resolvers/RenderParameters/RenderParametersResolver.swift index e1965ce..2760307 100644 --- a/Sources/FigmaGen/Resolvers/RenderParameters/RenderParametersResolver.swift +++ b/Sources/FigmaGen/Resolvers/RenderParameters/RenderParametersResolver.swift @@ -7,7 +7,6 @@ protocol RenderParametersResolver { defaultTemplateType: RenderTemplateType, defaultDestination: RenderDestination ) -> [RenderParameters]? - } extension RenderParametersResolver { @@ -23,5 +22,4 @@ extension RenderParametersResolver { defaultDestination: defaultDestination ) } - -} \ No newline at end of file +} From 0065b81a1f6d6d6c349eb6f1e2c4ef69393fa03f Mon Sep 17 00:00:00 2001 From: Timur Shafigullin Date: Tue, 19 Dec 2023 12:56:37 +0300 Subject: [PATCH 11/11] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83?= =?UTF-8?q?=D1=80=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BF=D0=BE=20=D1=83=D0=BC?= =?UTF-8?q?=D0=BE=D0=BB=D1=87=D0=B0=D0=BD=D0=B8=D1=8E=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DefaultColorStylesGenerator.swift | 14 ++++++-------- .../GenerationParametersResolving.swift | 6 +++--- .../Images/DefaultImagesGenerator.swift | 14 ++++++-------- .../DefaultShadowStylesGenerator.swift | 14 ++++++-------- .../TextStyles/DefaultTextStylesGenerator.swift | 14 ++++++-------- .../Models/Parameters/GenerationParameters.swift | 2 +- .../DefaultRenderParametersResolver.swift | 16 ++++++++++++---- .../RenderParametersResolver.swift | 9 ++++----- 8 files changed, 44 insertions(+), 45 deletions(-) diff --git a/Sources/FigmaGen/Generators/ColorStyles/DefaultColorStylesGenerator.swift b/Sources/FigmaGen/Generators/ColorStyles/DefaultColorStylesGenerator.swift index 4f833ac..032cfb0 100644 --- a/Sources/FigmaGen/Generators/ColorStyles/DefaultColorStylesGenerator.swift +++ b/Sources/FigmaGen/Generators/ColorStyles/DefaultColorStylesGenerator.swift @@ -40,14 +40,12 @@ final class DefaultColorStylesGenerator: ColorStylesGenerator, GenerationParamet }.map { colorStyles in ColorStylesContext(colorStyles: colorStyles) }.done { context in - if let renderParametersList = parameters.renderParameters { - for params in renderParametersList { - try self.templateRenderer.renderTemplate( - params.template, - to: params.destination, - context: context - ) - } + try parameters.renderParameters.forEach { params in + try self.templateRenderer.renderTemplate( + params.template, + to: params.destination, + context: context + ) } } } diff --git a/Sources/FigmaGen/Generators/GenerationParametersResolving.swift b/Sources/FigmaGen/Generators/GenerationParametersResolving.swift index c1382df..2f0b10e 100644 --- a/Sources/FigmaGen/Generators/GenerationParametersResolving.swift +++ b/Sources/FigmaGen/Generators/GenerationParametersResolving.swift @@ -26,9 +26,9 @@ extension GenerationParametersResolving { throw GenerationParametersError.invalidFileConfiguration } - guard let accessToken = accessTokenResolver.resolveAccessToken( - from: configuration.accessToken - ), !accessToken.isEmpty else { + let accessToken = accessTokenResolver.resolveAccessToken(from: configuration.accessToken) + + guard let accessToken, !accessToken.isEmpty else { throw GenerationParametersError.invalidAccessToken } diff --git a/Sources/FigmaGen/Generators/Images/DefaultImagesGenerator.swift b/Sources/FigmaGen/Generators/Images/DefaultImagesGenerator.swift index 18879aa..7a6673d 100644 --- a/Sources/FigmaGen/Generators/Images/DefaultImagesGenerator.swift +++ b/Sources/FigmaGen/Generators/Images/DefaultImagesGenerator.swift @@ -42,14 +42,12 @@ final class DefaultImagesGenerator: ImagesGenerator, GenerationParametersResolvi imageSets: imageSets.sorted { $0.name.lowercased() < $1.name.lowercased() } ) }.done { context in - if let renderParametersList = parameters.renderParameters { - for params in renderParametersList { - try self.templateRenderer.renderTemplate( - params.template, - to: params.destination, - context: context - ) - } + try parameters.renderParameters.forEach { params in + try self.templateRenderer.renderTemplate( + params.template, + to: params.destination, + context: context + ) } } } diff --git a/Sources/FigmaGen/Generators/ShadowStyles/DefaultShadowStylesGenerator.swift b/Sources/FigmaGen/Generators/ShadowStyles/DefaultShadowStylesGenerator.swift index ec46b46..0d67c66 100644 --- a/Sources/FigmaGen/Generators/ShadowStyles/DefaultShadowStylesGenerator.swift +++ b/Sources/FigmaGen/Generators/ShadowStyles/DefaultShadowStylesGenerator.swift @@ -36,14 +36,12 @@ final class DefaultShadowStylesGenerator: ShadowStylesGenerator, GenerationParam }.map { shadowStyles in ShadowStylesContext(shadowStyles: shadowStyles) }.done { context in - if let renderParametersList = parameters.renderParameters { - for params in renderParametersList { - try self.templateRenderer.renderTemplate( - params.template, - to: params.destination, - context: context - ) - } + try parameters.renderParameters.forEach { params in + try self.templateRenderer.renderTemplate( + params.template, + to: params.destination, + context: context + ) } } } diff --git a/Sources/FigmaGen/Generators/TextStyles/DefaultTextStylesGenerator.swift b/Sources/FigmaGen/Generators/TextStyles/DefaultTextStylesGenerator.swift index 3e5e272..86430aa 100644 --- a/Sources/FigmaGen/Generators/TextStyles/DefaultTextStylesGenerator.swift +++ b/Sources/FigmaGen/Generators/TextStyles/DefaultTextStylesGenerator.swift @@ -36,14 +36,12 @@ final class DefaultTextStylesGenerator: TextStylesGenerator, GenerationParameter }.map { textStyles in TextStylesContext(textStyles: textStyles) }.done { context in - if let renderParametersList = parameters.renderParameters { - for params in renderParametersList { - try self.templateRenderer.renderTemplate( - params.template, - to: params.destination, - context: context - ) - } + try parameters.renderParameters.forEach { params in + try self.templateRenderer.renderTemplate( + params.template, + to: params.destination, + context: context + ) } } } diff --git a/Sources/FigmaGen/Models/Parameters/GenerationParameters.swift b/Sources/FigmaGen/Models/Parameters/GenerationParameters.swift index 005d6b9..da69557 100644 --- a/Sources/FigmaGen/Models/Parameters/GenerationParameters.swift +++ b/Sources/FigmaGen/Models/Parameters/GenerationParameters.swift @@ -6,5 +6,5 @@ struct GenerationParameters { let file: FileParameters let nodes: NodesParameters - let renderParameters: [RenderParameters]? + let renderParameters: [RenderParameters] } diff --git a/Sources/FigmaGen/Resolvers/RenderParameters/DefaultRenderParametersResolver.swift b/Sources/FigmaGen/Resolvers/RenderParameters/DefaultRenderParametersResolver.swift index 70fd9c9..f3ac399 100644 --- a/Sources/FigmaGen/Resolvers/RenderParameters/DefaultRenderParametersResolver.swift +++ b/Sources/FigmaGen/Resolvers/RenderParameters/DefaultRenderParametersResolver.swift @@ -30,12 +30,20 @@ final class DefaultRenderParametersResolver: RenderParametersResolver { templates: [TemplateConfiguration]?, defaultTemplateType: RenderTemplateType, defaultDestination: RenderDestination - ) -> [RenderParameters]? { - guard let templateConfigurations = templates else { - return nil + ) -> [RenderParameters] { + let defaultRenderParameters = RenderParameters( + template: RenderTemplate( + type: defaultTemplateType, + options: [:] + ), + destination: defaultDestination + ) + + guard let templates else { + return [defaultRenderParameters] } - return templateConfigurations.map { template -> RenderParameters in + return templates.map { template in let templateType = resolveTemplateType( template: template, defaultTemplateType: defaultTemplateType diff --git a/Sources/FigmaGen/Resolvers/RenderParameters/RenderParametersResolver.swift b/Sources/FigmaGen/Resolvers/RenderParameters/RenderParametersResolver.swift index 2760307..7bdc90a 100644 --- a/Sources/FigmaGen/Resolvers/RenderParameters/RenderParametersResolver.swift +++ b/Sources/FigmaGen/Resolvers/RenderParameters/RenderParametersResolver.swift @@ -6,20 +6,19 @@ protocol RenderParametersResolver { templates: [TemplateConfiguration]?, defaultTemplateType: RenderTemplateType, defaultDestination: RenderDestination - ) -> [RenderParameters]? + ) -> [RenderParameters] } extension RenderParametersResolver { func resolveRenderParameters( templates: [TemplateConfiguration]?, - defaultTemplateType: RenderTemplateType, - defaultDestination: RenderDestination = .console - ) -> [RenderParameters]? { + defaultTemplateType: RenderTemplateType + ) -> [RenderParameters] { resolveRenderParameters( templates: templates, defaultTemplateType: defaultTemplateType, - defaultDestination: defaultDestination + defaultDestination: .console ) } }