Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --render-markdowns command flag and renderMarkdown spec option #1288

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- 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.
- Added `renderMarkdown` spec option generate the `.xcodesamplecode.plist` inside the project container and let Xcode render the markdown files with `md` extension.

### Fixed

Expand Down
4 changes: 4 additions & 0 deletions Sources/ProjectSpec/SpecOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down
36 changes: 36 additions & 0 deletions Sources/XcodeGenCLI/Commands/GenerateCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
MojtabaHs marked this conversation as resolved.
Show resolved Hide resolved

init(version: Version) {
super.init(version: version,
Expand Down Expand Up @@ -115,6 +118,39 @@ class GenerateCommand: ProjectCommand {
} catch {
throw GenerationError.writingError(error)
}

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
if let cacheFile = cacheFile {
Expand Down
10 changes: 10 additions & 0 deletions Sources/XcodeGenKit/FileWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ public class FileWriter {
}
}
}

public func writeMarkdownRendererPlist() throws {
let path = project.defaultProjectPath + ".xcodesamplecode.plist"
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
Expand Down