Read config path from command line
This commit is contained in:
parent
9965e1a3ff
commit
64db75fb44
@ -50,6 +50,12 @@
|
||||
ReferencedContainer = "container:WebsiteGenerator.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
<CommandLineArguments>
|
||||
<CommandLineArgument
|
||||
argument = "/Users/ch/Projects/MakerSpace/CHGenerator/config.json"
|
||||
isEnabled = "YES">
|
||||
</CommandLineArgument>
|
||||
</CommandLineArguments>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
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) {
|
||||
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 {
|
||||
let (content, includesCode) = PageContentGenerator(factory: factory.factory)
|
||||
.generate(page: page, language: language, content: raw)
|
||||
|
@ -1,10 +1,17 @@
|
||||
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
|
||||
do {
|
||||
let configUrl = URL(fileURLWithPath: args[1])
|
||||
let data = try Data(contentsOf: configUrl)
|
||||
configuration = try JSONDecoder().decode(from: data)
|
||||
} catch {
|
||||
|
Loading…
Reference in New Issue
Block a user