From 24f8ae15cf972adc911395686055f49ea9e8dd00 Mon Sep 17 00:00:00 2001 From: Seyed Mojtaba Hosseini Zeidabadi Date: Wed, 9 Nov 2022 17:17:15 +0330 Subject: [PATCH 1/7] Add: markdown renderer command flag --- Sources/XcodeGenCLI/Commands/GenerateCommand.swift | 13 +++++++++++++ Sources/XcodeGenKit/FileWriter.swift | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/Sources/XcodeGenCLI/Commands/GenerateCommand.swift b/Sources/XcodeGenCLI/Commands/GenerateCommand.swift index b786e563..d184d40c 100644 --- a/Sources/XcodeGenCLI/Commands/GenerateCommand.swift +++ b/Sources/XcodeGenCLI/Commands/GenerateCommand.swift @@ -22,6 +22,9 @@ class GenerateCommand: ProjectCommand { @Flag("--only-plists", description: "Generate only plist files") var onlyPlists: Bool + + @Flag("--render-markdowns", description: "Render markdown files with `.md` extension") + var renderMarkdowns: Bool init(version: Version) { super.init(version: version, @@ -115,6 +118,16 @@ class GenerateCommand: ProjectCommand { } catch { throw GenerationError.writingError(error) } + + // add markdown renderer if needed + if renderMarkdowns { + do { + try fileWriter.writeMarkdownRendererPlist() + success("Created markdown renderer in the project file") + } catch { + throw GenerationError.writingError(error) + } + } // write cache if let cacheFile = cacheFile { diff --git a/Sources/XcodeGenKit/FileWriter.swift b/Sources/XcodeGenKit/FileWriter.swift index 17af96c5..77bd5c61 100644 --- a/Sources/XcodeGenKit/FileWriter.swift +++ b/Sources/XcodeGenKit/FileWriter.swift @@ -40,6 +40,10 @@ public class FileWriter { } } } + + public func writeMarkdownRendererPlist() throws { + try writePlist([:], path: project.defaultProjectPath.string.appending("/.xcodesamplecode.plist")) + } private func writePlist(_ plist: [String: Any], path: String) throws { let path = project.basePath + path From 25ea10f50c973626684f1712c8c4914fefffdc3b Mon Sep 17 00:00:00 2001 From: Seyed Mojtaba Hosseini Zeidabadi Date: Wed, 9 Nov 2022 17:28:42 +0330 Subject: [PATCH 2/7] =?UTF-8?q?update=20changelog=20for=20the=20`=E2=80=94?= =?UTF-8?q?render-markdowns`=20command=20flag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4af2736..96e0489b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Config setting presets can now also be loaded from the main bundle when bundling XcodeGenKit #1135 @SofteqDG - Added ability to generate multiple projects in one XcodeGen launch #1270 @skofgar - Use memoization during recursive SpecFiles creation. This provides a drastic performance boost with lots of recursive includes #1275 @ma-oli +- Added `--render-markdowns` command flag to generate the `.xcodesamplecode.plist` inside the project container and let Xcode render the markdown files with `md` extension. ### Fixed From db0db75e63dce1a23927b1196642867fe5748a19 Mon Sep 17 00:00:00 2001 From: Seyed Mojtaba Hosseini Zeidabadi Date: Wed, 9 Nov 2022 18:19:00 +0330 Subject: [PATCH 3/7] cleaned xcodesamplecode.plist file generation code --- Sources/XcodeGenKit/FileWriter.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/XcodeGenKit/FileWriter.swift b/Sources/XcodeGenKit/FileWriter.swift index 77bd5c61..a2cea7b3 100644 --- a/Sources/XcodeGenKit/FileWriter.swift +++ b/Sources/XcodeGenKit/FileWriter.swift @@ -42,7 +42,8 @@ public class FileWriter { } public func writeMarkdownRendererPlist() throws { - try writePlist([:], path: project.defaultProjectPath.string.appending("/.xcodesamplecode.plist")) + let path = project.defaultProjectPath + ".xcodesamplecode.plist" + try writePlist([:], path: path.string) } private func writePlist(_ plist: [String: Any], path: String) throws { From f9db8c5449b0b97993749daf60dbe0692973ee90 Mon Sep 17 00:00:00 2001 From: Seyed Mojtaba Hosseini Zeidabadi Date: Wed, 9 Nov 2022 18:58:44 +0330 Subject: [PATCH 4/7] better message for enabeling xcode markdown rendering --- Sources/XcodeGenCLI/Commands/GenerateCommand.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/XcodeGenCLI/Commands/GenerateCommand.swift b/Sources/XcodeGenCLI/Commands/GenerateCommand.swift index d184d40c..253bfb00 100644 --- a/Sources/XcodeGenCLI/Commands/GenerateCommand.swift +++ b/Sources/XcodeGenCLI/Commands/GenerateCommand.swift @@ -123,7 +123,7 @@ class GenerateCommand: ProjectCommand { if renderMarkdowns { do { try fileWriter.writeMarkdownRendererPlist() - success("Created markdown renderer in the project file") + success("Xcode markdown rendering enabled") } catch { throw GenerationError.writingError(error) } From cafbf2dac36a6e9f254bdecd8347ebe00a949e5d Mon Sep 17 00:00:00 2001 From: Seyed Mojtaba Hosseini Zeidabadi Date: Tue, 22 Nov 2022 13:16:01 +0330 Subject: [PATCH 5/7] =?UTF-8?q?add:=20delete=20markdown=20renderer=20funct?= =?UTF-8?q?ion=20to=20remove=20it=20when=20it=E2=80=99s=20false?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/XcodeGenKit/FileWriter.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sources/XcodeGenKit/FileWriter.swift b/Sources/XcodeGenKit/FileWriter.swift index a2cea7b3..98edfee0 100644 --- a/Sources/XcodeGenKit/FileWriter.swift +++ b/Sources/XcodeGenKit/FileWriter.swift @@ -46,6 +46,11 @@ public class FileWriter { try writePlist([:], path: path.string) } + public func deleteMarkdownRendererPlist() throws { + let path = project.defaultProjectPath + ".xcodesamplecode.plist" + try path.delete() + } + private func writePlist(_ plist: [String: Any], path: String) throws { let path = project.basePath + path if path.exists, let data: Data = try? path.read(), From 9d64afa4bdf410bc03c33a9d09f69716af814f8d Mon Sep 17 00:00:00 2001 From: Seyed Mojtaba Hosseini Zeidabadi Date: Tue, 22 Nov 2022 13:17:35 +0330 Subject: [PATCH 6/7] add: mark down renderer spec option --- Sources/ProjectSpec/SpecOptions.swift | 4 +++ .../Commands/GenerateCommand.swift | 27 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Sources/ProjectSpec/SpecOptions.swift b/Sources/ProjectSpec/SpecOptions.swift index a5df4e28..96a76d15 100644 --- a/Sources/ProjectSpec/SpecOptions.swift +++ b/Sources/ProjectSpec/SpecOptions.swift @@ -16,6 +16,7 @@ public struct SpecOptions: Equatable { public var carthageBuildPath: String? public var carthageExecutablePath: String? public var createIntermediateGroups: Bool + public var renderMarkdowns: Bool? public var bundleIdPrefix: String? public var settingPresets: SettingPresets public var disabledValidations: [ValidationType] @@ -80,6 +81,7 @@ public struct SpecOptions: Equatable { carthageBuildPath: String? = nil, carthageExecutablePath: String? = nil, createIntermediateGroups: Bool = createIntermediateGroupsDefault, + renderMarkdowns: Bool? = nil, bundleIdPrefix: String? = nil, settingPresets: SettingPresets = settingPresetsDefault, developmentLanguage: String? = nil, @@ -106,6 +108,7 @@ public struct SpecOptions: Equatable { self.carthageBuildPath = carthageBuildPath self.carthageExecutablePath = carthageExecutablePath self.createIntermediateGroups = createIntermediateGroups + self.renderMarkdowns = renderMarkdowns self.bundleIdPrefix = bundleIdPrefix self.settingPresets = settingPresets self.developmentLanguage = developmentLanguage @@ -142,6 +145,7 @@ extension SpecOptions: JSONObjectConvertible { bundleIdPrefix = jsonDictionary.json(atKeyPath: "bundleIdPrefix") settingPresets = jsonDictionary.json(atKeyPath: "settingPresets") ?? SpecOptions.settingPresetsDefault createIntermediateGroups = jsonDictionary.json(atKeyPath: "createIntermediateGroups") ?? SpecOptions.createIntermediateGroupsDefault + renderMarkdowns = jsonDictionary.json(atKeyPath: "renderMarkdowns") developmentLanguage = jsonDictionary.json(atKeyPath: "developmentLanguage") usesTabs = jsonDictionary.json(atKeyPath: "usesTabs") xcodeVersion = jsonDictionary.json(atKeyPath: "xcodeVersion") diff --git a/Sources/XcodeGenCLI/Commands/GenerateCommand.swift b/Sources/XcodeGenCLI/Commands/GenerateCommand.swift index 253bfb00..b8477541 100644 --- a/Sources/XcodeGenCLI/Commands/GenerateCommand.swift +++ b/Sources/XcodeGenCLI/Commands/GenerateCommand.swift @@ -119,14 +119,37 @@ class GenerateCommand: ProjectCommand { throw GenerationError.writingError(error) } - // add markdown renderer if needed - if renderMarkdowns { + switch project.options.renderMarkdowns { + case .some(true): do { try fileWriter.writeMarkdownRendererPlist() success("Xcode markdown rendering enabled") } catch { throw GenerationError.writingError(error) } + case .some(false): + do { + try fileWriter.deleteMarkdownRendererPlist() + success("Xcode markdown rendering disabled") + } catch { + info("Failed to disable Xcode markdown rendering: \(error.localizedDescription)") + } + case .none: break + // No need for change + } + + // add markdown renderer if needed + /// - Note: this flag will override the spec option + if renderMarkdowns && project.options.renderMarkdowns != true { + do { + if project.options.renderMarkdowns == false { + info("Overriding markdown rendering option because of the given --render-markdowns flag") + } + try fileWriter.writeMarkdownRendererPlist() + success("Xcode markdown rendering enabled") + } catch { + throw GenerationError.writingError(error) + } } // write cache From 2f2fd653707906f978eb120dc2805ff1ab2b6536 Mon Sep 17 00:00:00 2001 From: Seyed Mojtaba Hosseini Zeidabadi Date: Tue, 22 Nov 2022 13:18:03 +0330 Subject: [PATCH 7/7] docs: update the change log for `renderMarkdown` spec option --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96e0489b..15060b92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Added ability to generate multiple projects in one XcodeGen launch #1270 @skofgar - Use memoization during recursive SpecFiles creation. This provides a drastic performance boost with lots of recursive includes #1275 @ma-oli - Added `--render-markdowns` command flag to generate the `.xcodesamplecode.plist` inside the project container and let Xcode render the markdown files with `md` extension. +- Added `renderMarkdown` spec option generate the `.xcodesamplecode.plist` inside the project container and let Xcode render the markdown files with `md` extension. ### Fixed