CHGenerator/Sources/Generator/run.swift

45 lines
1.1 KiB
Swift
Raw Normal View History

2022-09-09 13:29:31 +02:00
import Foundation
import ArgumentParser
var configuration: Configuration!
let log = ValidationLog()
var files: FileSystem!
2022-09-23 09:22:38 +02:00
var siteRoot: Element!
2022-09-09 13:29:31 +02:00
@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)
2022-09-23 09:22:38 +02:00
siteRoot = Element(atRoot: configuration.contentDirectory)
guard siteRoot != nil else {
2022-09-09 13:29:31 +02:00
return
}
let siteGenerator = try SiteGenerator()
2022-09-23 09:22:38 +02:00
siteGenerator.generate(site: siteRoot)
2022-09-09 13:29:31 +02:00
files.printGeneratedPages()
files.printEmptyPages()
files.printDraftPages()
files.createImages()
files.copyRequiredFiles()
files.printExternalFiles()
2022-09-18 16:48:15 +02:00
files.writeDetectedFileChangesToDisk()
2022-09-09 13:29:31 +02:00
}