From 570cebb5d0a1b66c0f2a04e64c85c2d7fbd10e24 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Thu, 8 Sep 2022 09:33:27 +0200 Subject: [PATCH] Read generator configuration from file --- WebsiteGenerator/Files/Configuration.swift | 2 +- WebsiteGenerator/main.swift | 20 +++++++++++++------- config_example.json | 6 ++++++ 3 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 config_example.json diff --git a/WebsiteGenerator/Files/Configuration.swift b/WebsiteGenerator/Files/Configuration.swift index 1fcc037..e4e99ff 100644 --- a/WebsiteGenerator/Files/Configuration.swift +++ b/WebsiteGenerator/Files/Configuration.swift @@ -1,6 +1,6 @@ import Foundation -struct Configuration { +struct Configuration: Codable { let pageImageWidth: Int diff --git a/WebsiteGenerator/main.swift b/WebsiteGenerator/main.swift index 06d2bc3..5b76433 100644 --- a/WebsiteGenerator/main.swift +++ b/WebsiteGenerator/main.swift @@ -1,11 +1,16 @@ import Foundation -let configuration = Configuration( - pageImageWidth: <#T##Int#>, - minifyCSSandJS: <#T##Bool#>, - contentPath: <#T##String#>, - outputPath: <#T##String#>) +let configUrl = URL(fileURLWithPath: "/Users/ch/Projects/MakerSpace/CHGenerator/config.json") + +let configuration: Configuration +do { + let data = try Data(contentsOf: configUrl) + configuration = try JSONDecoder().decode(from: data) +} catch { + print("Failed to read configuration: \(error)") + exit(1) +} let log = ValidationLog() let files = FileSystem( @@ -20,8 +25,8 @@ do { let siteGenerator = try SiteGenerator() siteGenerator.generate(site: siteData) } catch { - print(error) - exit(0) + print("Failed to generate website: \(error)") + exit(2) } files.printGeneratedPages() @@ -31,4 +36,5 @@ files.printDraftPages() files.createImages() print("Images generated") files.copyRequiredFiles() +files.printExternalFiles() files.writeHashes() diff --git a/config_example.json b/config_example.json new file mode 100644 index 0000000..8ed1ca1 --- /dev/null +++ b/config_example.json @@ -0,0 +1,6 @@ +{ + "pageImageWidth" : 748, + "minifyCSSandJS" : true, + "contentPath" : "/path/to/content/folder", + "outputPath" : "/path/to/output/folder") +}