CHGenerator/Sources/Generator/run.swift

56 lines
1.5 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 loadSiteData(in folder: URL) throws -> Element? {
let log = MetadataInfoLogger(input: folder)
print("--- SOURCE FILES -----------------------------------")
let root = Element(atRoot: folder, log: log)
print(" ")
log.printMetadataScanOverview()
try log.writeResultsToFile(in: files.generatorInfoFolder)
return root
}
2022-09-09 13:29:31 +02:00
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)
// 2. Scan site elements
siteRoot = try loadSiteData(in: configuration.contentDirectory)
2022-09-23 09:22:38 +02:00
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
}