Read config path from command line
This commit is contained in:
parent
9965e1a3ff
commit
64db75fb44
@ -50,6 +50,12 @@
|
|||||||
ReferencedContainer = "container:WebsiteGenerator.xcodeproj">
|
ReferencedContainer = "container:WebsiteGenerator.xcodeproj">
|
||||||
</BuildableReference>
|
</BuildableReference>
|
||||||
</BuildableProductRunnable>
|
</BuildableProductRunnable>
|
||||||
|
<CommandLineArguments>
|
||||||
|
<CommandLineArgument
|
||||||
|
argument = "/Users/ch/Projects/MakerSpace/CHGenerator/config.json"
|
||||||
|
isEnabled = "YES">
|
||||||
|
</CommandLineArgument>
|
||||||
|
</CommandLineArguments>
|
||||||
</LaunchAction>
|
</LaunchAction>
|
||||||
<ProfileAction
|
<ProfileAction
|
||||||
buildConfiguration = "Release"
|
buildConfiguration = "Release"
|
||||||
|
@ -59,7 +59,8 @@ struct PageGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func makeContent(page: Element, metadata: Element.LocalizedMetadata, language: String, path: String) -> (content: String, includesCode: Bool, isEmpty: Bool) {
|
private func makeContent(page: Element, metadata: Element.LocalizedMetadata, language: String, path: String) -> (content: String, includesCode: Bool, isEmpty: Bool) {
|
||||||
if let raw = files.contentOfOptionalFile(atPath: path, source: page.path, createEmptyFileIfMissing: true)?
|
let create = configuration.createMdFilesIfMissing
|
||||||
|
if let raw = files.contentOfOptionalFile(atPath: path, source: page.path, createEmptyFileIfMissing: create)?
|
||||||
.trimmed.nonEmpty {
|
.trimmed.nonEmpty {
|
||||||
let (content, includesCode) = PageContentGenerator(factory: factory.factory)
|
let (content, includesCode) = PageContentGenerator(factory: factory.factory)
|
||||||
.generate(page: page, language: language, content: raw)
|
.generate(page: page, language: language, content: raw)
|
||||||
|
@ -1,10 +1,17 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
|
||||||
let configUrl = URL(fileURLWithPath: "/Users/ch/Projects/MakerSpace/CHGenerator/config.json")
|
let args = CommandLine.arguments
|
||||||
|
|
||||||
|
guard args.count == 2 else {
|
||||||
|
print("Invalid argument list")
|
||||||
|
print("Usage: generator config-path")
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
let configuration: Configuration
|
let configuration: Configuration
|
||||||
do {
|
do {
|
||||||
|
let configUrl = URL(fileURLWithPath: args[1])
|
||||||
let data = try Data(contentsOf: configUrl)
|
let data = try Data(contentsOf: configUrl)
|
||||||
configuration = try JSONDecoder().decode(from: data)
|
configuration = try JSONDecoder().decode(from: data)
|
||||||
} catch {
|
} catch {
|
||||||
|
Loading…
Reference in New Issue
Block a user