Read generator configuration from file

This commit is contained in:
Christoph Hagen 2022-09-08 09:33:27 +02:00
parent 81b373fb5a
commit 570cebb5d0
3 changed files with 20 additions and 8 deletions

View File

@ -1,6 +1,6 @@
import Foundation
struct Configuration {
struct Configuration: Codable {
let pageImageWidth: Int

View File

@ -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()

6
config_example.json Normal file
View File

@ -0,0 +1,6 @@
{
"pageImageWidth" : 748,
"minifyCSSandJS" : true,
"contentPath" : "/path/to/content/folder",
"outputPath" : "/path/to/output/folder")
}