CHGenerator/Sources/Generator/run.swift

44 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!
@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)
guard let siteData = Element(atRoot: configuration.contentDirectory) else {
return
}
let siteGenerator = try SiteGenerator()
siteGenerator.generate(site: siteData)
files.printGeneratedPages()
files.printEmptyPages()
files.printDraftPages()
files.createImages()
print("Images generated")
files.copyRequiredFiles()
files.printExternalFiles()
files.writeHashes()
}