2022-09-09 13:29:31 +02:00
|
|
|
import Foundation
|
|
|
|
import ArgumentParser
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-01 14:50:26 +01:00
|
|
|
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()
|
2022-12-01 15:03:29 +01:00
|
|
|
print(" ")
|
2022-12-01 14:50:26 +01:00
|
|
|
try log.writeResultsToFile(in: files.generatorInfoFolder)
|
|
|
|
return root
|
|
|
|
}
|
|
|
|
|
2022-12-01 15:19:17 +01:00
|
|
|
private func loadConfiguration(at configPath: String) -> Configuration? {
|
|
|
|
print("--- CONFIGURATION ----------------------------------")
|
|
|
|
print("")
|
|
|
|
print(" Configuration file: \(configPath)")
|
2022-09-09 13:29:31 +02:00
|
|
|
let configUrl = URL(fileURLWithPath: configPath)
|
2022-12-01 15:19:17 +01:00
|
|
|
let config: Configuration
|
|
|
|
do {
|
|
|
|
let data = try Data(contentsOf: configUrl)
|
|
|
|
config = try JSONDecoder().decode(from: data)
|
|
|
|
} catch {
|
|
|
|
print(" Configuration error: \(error)")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
config.printOverview()
|
|
|
|
print(" ")
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
|
|
|
private func generate(configPath: String) throws {
|
|
|
|
guard let configuration = loadConfiguration(at: configPath) else {
|
|
|
|
return
|
|
|
|
}
|
2022-09-09 13:29:31 +02:00
|
|
|
|
|
|
|
files = .init(
|
|
|
|
in: configuration.contentDirectory,
|
2022-12-01 15:19:17 +01:00
|
|
|
to: configuration.outputDirectory,
|
|
|
|
configuration: configuration)
|
|
|
|
|
2022-09-09 13:29:31 +02:00
|
|
|
|
2022-12-01 14:50:26 +01:00
|
|
|
// 2. Scan site elements
|
2022-12-01 15:25:55 +01:00
|
|
|
guard let siteRoot = try loadSiteData(in: configuration.contentDirectory) 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
|
|
|
}
|