From 10112e61d66429a0d72b310062e1c00ca53fdf12 Mon Sep 17 00:00:00 2001 From: Jeff Pearce Date: Fri, 4 Oct 2024 07:27:52 -0700 Subject: [PATCH 1/2] Add ability to customize start/end of each generated file --- Cuckoofile.toml | 7 +++++++ Generator/Sources/CLI/GenerateCommand.swift | 4 ++-- Generator/Sources/CLI/Module.swift | 8 +++++++- README.md | 12 +++++++++++- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Cuckoofile.toml b/Cuckoofile.toml index 3a534806..d759c36f 100644 --- a/Cuckoofile.toml +++ b/Cuckoofile.toml @@ -12,10 +12,17 @@ exclude = [ ] # regex = "" output = "Tests/Swift/Generated/GeneratedMocks.swift" +# output = "Tests/Swift/Generated/" [modules.Cuckoo.options] glob = true keepDocumentation = false +filePrefix = [ + "// swiftlint:disable all", +] +fileSuffix = [ + "// swiftlint:enable all", +] [modules.Cuckoo.xcodeproj] path = "Generator" diff --git a/Generator/Sources/CLI/GenerateCommand.swift b/Generator/Sources/CLI/GenerateCommand.swift index db77fbad..64c926ee 100644 --- a/Generator/Sources/CLI/GenerateCommand.swift +++ b/Generator/Sources/CLI/GenerateCommand.swift @@ -88,7 +88,7 @@ struct GenerateCommand: AsyncParsableCommand { ?? originalFileName let outputFile = TextFile(path: absoluteOutputPath + "\(fileNameWithoutExtension).swift") do { - try outputFile.write(generatedFile.contents) + try outputFile.write(module.options.filePrefix + generatedFile.contents + module.options.fileSuffix) } catch { log(.error, message: "Failed to write to file '\(outputFile)':", error) } @@ -96,7 +96,7 @@ struct GenerateCommand: AsyncParsableCommand { } else { let outputFile = TextFile(path: absoluteOutputPath) do { - try outputFile.write(generatedFiles.map(\.contents).joined(separator: "\n\n")) + try outputFile.write(module.options.filePrefix + generatedFiles.map(\.contents).joined(separator: "\n\n") + module.options.filePrefix) } catch { log(.error, message: "Failed to write to file '\(outputFile)':", error) } diff --git a/Generator/Sources/CLI/Module.swift b/Generator/Sources/CLI/Module.swift index ed0d5dc6..899ee195 100644 --- a/Generator/Sources/CLI/Module.swift +++ b/Generator/Sources/CLI/Module.swift @@ -35,7 +35,9 @@ final class Module { keepDocumentation: dto.options?.keepDocumentation ?? true, enableInheritance: dto.options?.enableInheritance ?? true, protocolsOnly: dto.options?.protocolsOnly ?? false, - omitHeaders: dto.options?.omitHeaders ?? false + omitHeaders: dto.options?.omitHeaders ?? false, + filePrefix: dto.options?.filePrefix?.joined(separator: "\n").appending("\n") ?? "", + fileSuffix: dto.options?.fileSuffix?.joined(separator: "\n").appending("\n") ?? "" ) if let xcodeproj = dto.xcodeproj { @@ -64,6 +66,8 @@ final class Module { let enableInheritance: Bool let protocolsOnly: Bool let omitHeaders: Bool + let filePrefix: String + let fileSuffix: String } struct Xcodeproj { @@ -107,6 +111,8 @@ extension Module { let enableInheritance: Bool? let protocolsOnly: Bool? let omitHeaders: Bool? + let filePrefix: [String]? + let fileSuffix: [String]? } struct Xcodeproj: Decodable { diff --git a/README.md b/README.md index aa0d408b..22b4f006 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,8 @@ sources = [ "Tests/Swift/Source/*.swift", ] exclude = ["ExcludedTestClass"] -# Optionally you can use a regular expression to filter only specific classes/protocols. + +s# Optionally you can use a regular expression to filter only specific classes/protocols. # regex = "" [modules.MyProject.options] @@ -137,6 +138,15 @@ keepDocumentation = false # protocolsOnly = true # omitHeaders = true +# You can add prefix lines to the beginning of each file written, and suffix lines to the end +# For example, this config can be used to turn swiftlint off at the start and back on at the end +prefixLines = [ + "// swiftlint:disable all", +] +SuffixLines = [ + "// swiftlint:enable all", +] + # If specified, Cuckoo can also get sources for the module from an Xcode target. [modules.MyProject.xcodeproj] # Path to folder with .xcodeproj, omit this if it's at the same level as Cuckoofile. From 72c101b5314e65cece1b7993c54259cd701cbdc7 Mon Sep 17 00:00:00 2001 From: Jeff Pearce Date: Fri, 4 Oct 2024 07:39:29 -0700 Subject: [PATCH 2/2] Fix README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 22b4f006..4923f2aa 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ sources = [ ] exclude = ["ExcludedTestClass"] -s# Optionally you can use a regular expression to filter only specific classes/protocols. +# Optionally you can use a regular expression to filter only specific classes/protocols. # regex = "" [modules.MyProject.options]