From 9f227aedc376343139131cbb2bb47dbceb7ae6a5 Mon Sep 17 00:00:00 2001 From: Christopher Fuller Date: Mon, 3 Mar 2025 13:24:02 -0800 Subject: [PATCH] Add config for interface imports --- Sources/NodesGenerator/Config.swift | 5 ++++ Sources/NodesGenerator/StencilTemplate.swift | 1 + Tests/NodesGeneratorTests/ConfigTests.swift | 3 ++ .../StencilTemplateTests.swift | 2 ++ .../Support/TestFactories.swift | 1 + .../ConfigTests/testConfig.1.txt | 3 ++ .../testConfigWithEmptyFileContents.1.txt | 1 + .../testDecodingFromEmptyString.1.txt | 1 + .../testDecodingWithEmptyArray.1.txt | 1 + ...ViewInjectedXcodeTemplatePermutation.1.txt | 3 +- ...on.AppKit-SwiftUI-CreatedForPluginList.txt | 3 +- ...codeTemplatePermutation.AppKit-SwiftUI.txt | 3 +- ...estNodeXcodeTemplatePermutation.AppKit.txt | 3 +- ...Permutation.AppKitCreatedForPluginList.txt | 3 +- ...estNodeXcodeTemplatePermutation.Custom.txt | 3 +- ...Permutation.CustomCreatedForPluginList.txt | 3 +- ...ion.UIKit-SwiftUI-CreatedForPluginList.txt | 3 +- ...XcodeTemplatePermutation.UIKit-SwiftUI.txt | 3 +- ...testNodeXcodeTemplatePermutation.UIKit.txt | 3 +- ...ePermutation.UIKitCreatedForPluginList.txt | 3 +- .../testNodeViewInjectedXcodeTemplate.1.txt | 3 +- .../testNodeXcodeTemplate.1.txt | 30 ++++++++++++------- 22 files changed, 62 insertions(+), 22 deletions(-) diff --git a/Sources/NodesGenerator/Config.swift b/Sources/NodesGenerator/Config.swift index 6da59c7ca..26ffce943 100644 --- a/Sources/NodesGenerator/Config.swift +++ b/Sources/NodesGenerator/Config.swift @@ -38,6 +38,7 @@ public struct Config: Codable, Equatable { public var dependencyInjectionImports: Set public var builderImports: Set public var flowImports: Set + public var interfaceImports: Set public var pluginListImports: Set public var viewControllerImports: Set public var dependencies: [Variable] @@ -94,6 +95,7 @@ extension Config { dependencyInjectionImports = ["NeedleFoundation"] builderImports = [] flowImports = [] + interfaceImports = [] pluginListImports = [] viewControllerImports = [] dependencies = [] @@ -168,6 +170,9 @@ extension Config { flowImports = (try? decoder.decode(CodingKeys.flowImports)) ?? defaults.flowImports + interfaceImports = + (try? decoder.decode(CodingKeys.interfaceImports)) + ?? defaults.interfaceImports pluginListImports = (try? decoder.decode(CodingKeys.pluginListImports)) ?? defaults.pluginListImports diff --git a/Sources/NodesGenerator/StencilTemplate.swift b/Sources/NodesGenerator/StencilTemplate.swift index 09a1ef263..72bf5c07d 100644 --- a/Sources/NodesGenerator/StencilTemplate.swift +++ b/Sources/NodesGenerator/StencilTemplate.swift @@ -287,6 +287,7 @@ public enum StencilTemplate: CustomStringConvertible, Equatable, Sendable { case .interface: config.baseImports .union(["Nodes"]) + .union(config.interfaceImports) case .plugin: config.baseImports .union(["Nodes"]) diff --git a/Tests/NodesGeneratorTests/ConfigTests.swift b/Tests/NodesGeneratorTests/ConfigTests.swift index 60ca91806..fca9dd291 100644 --- a/Tests/NodesGeneratorTests/ConfigTests.swift +++ b/Tests/NodesGeneratorTests/ConfigTests.swift @@ -157,6 +157,9 @@ final class ConfigTests: XCTestCase, TestFactories { flowImports: - - + interfaceImports: + - + - pluginListImports: - - diff --git a/Tests/NodesGeneratorTests/StencilTemplateTests.swift b/Tests/NodesGeneratorTests/StencilTemplateTests.swift index 1c9b2be43..301350968 100644 --- a/Tests/NodesGeneratorTests/StencilTemplateTests.swift +++ b/Tests/NodesGeneratorTests/StencilTemplateTests.swift @@ -341,6 +341,7 @@ final class StencilTemplateTests: XCTestCase, TestFactories { case .interface: expect(imports) == [ "", + "", "Nodes" ] case .plugin: @@ -466,6 +467,7 @@ final class StencilTemplateTests: XCTestCase, TestFactories { case .interface: expect(imports) == [ "", + "", "Nodes" ] case .plugin: diff --git a/Tests/NodesGeneratorTests/Support/TestFactories.swift b/Tests/NodesGeneratorTests/Support/TestFactories.swift index 45b9ef351..739864f12 100644 --- a/Tests/NodesGeneratorTests/Support/TestFactories.swift +++ b/Tests/NodesGeneratorTests/Support/TestFactories.swift @@ -34,6 +34,7 @@ extension TestFactories { config.dependencyInjectionImports = [""] config.builderImports = [""] config.flowImports = [""] + config.interfaceImports = [""] config.pluginListImports = [""] config.viewControllerImports = [""] config.dependencies = [Variable(name: "", type: "")] diff --git a/Tests/NodesGeneratorTests/__Snapshots__/ConfigTests/testConfig.1.txt b/Tests/NodesGeneratorTests/__Snapshots__/ConfigTests/testConfig.1.txt index 0b458768c..a6d1f8876 100644 --- a/Tests/NodesGeneratorTests/__Snapshots__/ConfigTests/testConfig.1.txt +++ b/Tests/NodesGeneratorTests/__Snapshots__/ConfigTests/testConfig.1.txt @@ -38,6 +38,9 @@ ▿ Variable - name: "" - type: "" + ▿ interfaceImports: 2 members + - "" + - "" - isObservableStoreEnabled: false - isPeripheryCommentEnabled: true - isPreviewProviderEnabled: true diff --git a/Tests/NodesGeneratorTests/__Snapshots__/ConfigTests/testConfigWithEmptyFileContents.1.txt b/Tests/NodesGeneratorTests/__Snapshots__/ConfigTests/testConfigWithEmptyFileContents.1.txt index c74f85b43..590927a65 100644 --- a/Tests/NodesGeneratorTests/__Snapshots__/ConfigTests/testConfigWithEmptyFileContents.1.txt +++ b/Tests/NodesGeneratorTests/__Snapshots__/ConfigTests/testConfigWithEmptyFileContents.1.txt @@ -12,6 +12,7 @@ - "NeedleFoundation" - flowImports: 0 members - flowProperties: 0 elements + - interfaceImports: 0 members - isObservableStoreEnabled: false - isPeripheryCommentEnabled: false - isPreviewProviderEnabled: false diff --git a/Tests/NodesGeneratorTests/__Snapshots__/ConfigTests/testDecodingFromEmptyString.1.txt b/Tests/NodesGeneratorTests/__Snapshots__/ConfigTests/testDecodingFromEmptyString.1.txt index c74f85b43..590927a65 100644 --- a/Tests/NodesGeneratorTests/__Snapshots__/ConfigTests/testDecodingFromEmptyString.1.txt +++ b/Tests/NodesGeneratorTests/__Snapshots__/ConfigTests/testDecodingFromEmptyString.1.txt @@ -12,6 +12,7 @@ - "NeedleFoundation" - flowImports: 0 members - flowProperties: 0 elements + - interfaceImports: 0 members - isObservableStoreEnabled: false - isPeripheryCommentEnabled: false - isPreviewProviderEnabled: false diff --git a/Tests/NodesGeneratorTests/__Snapshots__/ConfigTests/testDecodingWithEmptyArray.1.txt b/Tests/NodesGeneratorTests/__Snapshots__/ConfigTests/testDecodingWithEmptyArray.1.txt index c74f85b43..590927a65 100644 --- a/Tests/NodesGeneratorTests/__Snapshots__/ConfigTests/testDecodingWithEmptyArray.1.txt +++ b/Tests/NodesGeneratorTests/__Snapshots__/ConfigTests/testDecodingWithEmptyArray.1.txt @@ -12,6 +12,7 @@ - "NeedleFoundation" - flowImports: 0 members - flowProperties: 0 elements + - interfaceImports: 0 members - isObservableStoreEnabled: false - isPeripheryCommentEnabled: false - isPreviewProviderEnabled: false diff --git a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeViewInjectedXcodeTemplatePermutation.1.txt b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeViewInjectedXcodeTemplatePermutation.1.txt index 45b9865de..fa0e20d2e 100644 --- a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeViewInjectedXcodeTemplatePermutation.1.txt +++ b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeViewInjectedXcodeTemplatePermutation.1.txt @@ -55,8 +55,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true diff --git a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.AppKit-SwiftUI-CreatedForPluginList.txt b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.AppKit-SwiftUI-CreatedForPluginList.txt index 46a59cbdc..2ff34f45e 100644 --- a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.AppKit-SwiftUI-CreatedForPluginList.txt +++ b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.AppKit-SwiftUI-CreatedForPluginList.txt @@ -56,8 +56,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true diff --git a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.AppKit-SwiftUI.txt b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.AppKit-SwiftUI.txt index 8fa546d51..0dedfe616 100644 --- a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.AppKit-SwiftUI.txt +++ b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.AppKit-SwiftUI.txt @@ -56,8 +56,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true diff --git a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.AppKit.txt b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.AppKit.txt index e85d5d811..a631e6913 100644 --- a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.AppKit.txt +++ b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.AppKit.txt @@ -56,8 +56,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true diff --git a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.AppKitCreatedForPluginList.txt b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.AppKitCreatedForPluginList.txt index c6def65e2..b1c1fab8a 100644 --- a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.AppKitCreatedForPluginList.txt +++ b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.AppKitCreatedForPluginList.txt @@ -56,8 +56,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true diff --git a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.Custom.txt b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.Custom.txt index 603c25838..1d1f9e4b0 100644 --- a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.Custom.txt +++ b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.Custom.txt @@ -56,8 +56,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true diff --git a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.CustomCreatedForPluginList.txt b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.CustomCreatedForPluginList.txt index 43ce28b15..4b53e373f 100644 --- a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.CustomCreatedForPluginList.txt +++ b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.CustomCreatedForPluginList.txt @@ -56,8 +56,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true diff --git a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.UIKit-SwiftUI-CreatedForPluginList.txt b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.UIKit-SwiftUI-CreatedForPluginList.txt index 8e317587f..3c9badec9 100644 --- a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.UIKit-SwiftUI-CreatedForPluginList.txt +++ b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.UIKit-SwiftUI-CreatedForPluginList.txt @@ -56,8 +56,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true diff --git a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.UIKit-SwiftUI.txt b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.UIKit-SwiftUI.txt index 5276bca0d..711da9518 100644 --- a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.UIKit-SwiftUI.txt +++ b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.UIKit-SwiftUI.txt @@ -56,8 +56,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true diff --git a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.UIKit.txt b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.UIKit.txt index 13b67a8f6..e81622938 100644 --- a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.UIKit.txt +++ b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.UIKit.txt @@ -56,8 +56,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true diff --git a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.UIKitCreatedForPluginList.txt b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.UIKitCreatedForPluginList.txt index e6cdeeca8..34629a547 100644 --- a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.UIKitCreatedForPluginList.txt +++ b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplatePermutationTests/testNodeXcodeTemplatePermutation.UIKitCreatedForPluginList.txt @@ -56,8 +56,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true diff --git a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplateTests/testNodeViewInjectedXcodeTemplate.1.txt b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplateTests/testNodeViewInjectedXcodeTemplate.1.txt index 253fba433..3e46cc04a 100644 --- a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplateTests/testNodeViewInjectedXcodeTemplate.1.txt +++ b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplateTests/testNodeViewInjectedXcodeTemplate.1.txt @@ -58,8 +58,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true diff --git a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplateTests/testNodeXcodeTemplate.1.txt b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplateTests/testNodeXcodeTemplate.1.txt index ceca194e1..e5bb44cd4 100644 --- a/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplateTests/testNodeXcodeTemplate.1.txt +++ b/Tests/NodesGeneratorTests/__Snapshots__/XcodeTemplateTests/testNodeXcodeTemplate.1.txt @@ -59,8 +59,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true @@ -193,8 +194,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true @@ -327,8 +329,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true @@ -461,8 +464,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true @@ -595,8 +599,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true @@ -729,8 +734,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true @@ -863,8 +869,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true @@ -997,8 +1004,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true @@ -1131,8 +1139,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true @@ -1265,8 +1274,9 @@ - value: "" ▿ flowTestsImports: 1 element - "" - ▿ interfaceImports: 2 elements + ▿ interfaceImports: 3 elements - "" + - "" - "Nodes" - isNimbleEnabled: false - isPeripheryCommentEnabled: true