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 loadSiteData(in folder: URL) throws -> Element? { let log = MetadataInfoLogger(input: folder) print("--- SOURCE FILES -----------------------------------") let root = Element(atRoot: folder, log: log) print(" ") log.printMetadataScanOverview() print(" ") try log.writeResultsToFile(in: files.generatorInfoFolder) return root } 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) 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() }