45 lines
1.1 KiB
Swift
45 lines
1.1 KiB
Swift
import Foundation
|
|
import ArgumentParser
|
|
|
|
var configuration: Configuration!
|
|
let log = ValidationLog()
|
|
var files: FileSystem!
|
|
var siteRoot: Element!
|
|
|
|
@main
|
|
struct CHGenerator: ParsableCommand {
|
|
|
|
@Argument(help: "The path to the generator configuration file")
|
|
var configPath: String
|
|
|
|
mutating func run() throws {
|
|
try generate(configPath: configPath)
|
|
}
|
|
}
|
|
|
|
private func generate(configPath: String) throws {
|
|
let configUrl = URL(fileURLWithPath: configPath)
|
|
let data = try Data(contentsOf: configUrl)
|
|
configuration = try JSONDecoder().decode(from: data)
|
|
|
|
files = .init(
|
|
in: configuration.contentDirectory,
|
|
to: configuration.outputDirectory)
|
|
|
|
siteRoot = Element(atRoot: configuration.contentDirectory)
|
|
guard siteRoot != nil else {
|
|
return
|
|
}
|
|
let siteGenerator = try SiteGenerator()
|
|
siteGenerator.generate(site: siteRoot)
|
|
|
|
files.printGeneratedPages()
|
|
files.printEmptyPages()
|
|
files.printDraftPages()
|
|
|
|
files.createImages()
|
|
files.copyRequiredFiles()
|
|
files.printExternalFiles()
|
|
files.writeDetectedFileChangesToDisk()
|
|
}
|