From 31923974a6317664e20886cd03c741dd7483e703 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Sat, 10 Dec 2022 22:28:39 +0100 Subject: [PATCH] Split minify options for CSS and JS --- Sources/Generator/Files/Configuration.swift | 18 +++++++++++++----- .../Processing/GenerationResultsHandler.swift | 4 ++-- Sources/Generator/run.swift | 4 ++++ config_example.json | 4 +++- install.sh | 7 ++----- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/Sources/Generator/Files/Configuration.swift b/Sources/Generator/Files/Configuration.swift index b610cfa..47f3b22 100644 --- a/Sources/Generator/Files/Configuration.swift +++ b/Sources/Generator/Files/Configuration.swift @@ -21,12 +21,20 @@ struct Configuration: Codable { let fullScreenImageWidth: Int /** - Automatically minify all `.css` and `.js` resources which are copied + Automatically minify all `.css` resources which are copied to the output folder. - - Note: This option requires the `uglifyjs` and `clean-css` tools, + - Note: This option requires the `clean-css` tool, which can be installed using the `install.sh` script in the root folder of the generator. */ - let minifyCSSandJS: Bool + let minifyCSS: Bool + + /** + Automatically minify all `.js` resources which are copied + to the output folder. + - Note: This option requires the `uglifyjs` tool, + which can be installed using the `install.sh` script in the root folder of the generator. + */ + let minifyJavaScript: Bool /** The path to the directory where the root element metadata is located. @@ -76,8 +84,8 @@ struct Configuration: Codable { print(" Output folder: \(outputDirectory.path)") print(" Page width: \(pageImageWidth)") print(" Full-screen width: \(fullScreenImageWidth)") - print(" Minify JavaScript: \(minifyCSSandJS)") - print(" Minify CSS: \(minifyCSSandJS)") + print(" Minify JavaScript: \(minifyJavaScript)") + print(" Minify CSS: \(minifyCSS)") print(" Create markdown files: \(createMdFilesIfMissing)") } } diff --git a/Sources/Generator/Processing/GenerationResultsHandler.swift b/Sources/Generator/Processing/GenerationResultsHandler.swift index 0328d29..c0e6584 100644 --- a/Sources/Generator/Processing/GenerationResultsHandler.swift +++ b/Sources/Generator/Processing/GenerationResultsHandler.swift @@ -155,11 +155,11 @@ final class GenerationResultsHandler { private func markForCopyOrMinification(file: String, source: String) { let ext = file.lastComponentAfter(".") - if configuration.minifyCSSandJS, ext == "js" { + if configuration.minifyJavaScript, ext == "js" { files.toMinify[file] = (source, .js) return } - if configuration.minifyCSSandJS, ext == "css" { + if configuration.minifyCSS, ext == "css" { files.toMinify[file] = (source, .css) return } diff --git a/Sources/Generator/run.swift b/Sources/Generator/run.swift index 3fe19ed..f905328 100644 --- a/Sources/Generator/run.swift +++ b/Sources/Generator/run.swift @@ -18,6 +18,10 @@ private func loadConfiguration(at configPath: String) -> Configuration? { print(" ") print(" Configuration file: \(configPath)") let configUrl = URL(fileURLWithPath: configPath) + guard configUrl.exists else { + print(" Error: Configuration file not found") + return nil + } var config: Configuration do { let data = try Data(contentsOf: configUrl) diff --git a/config_example.json b/config_example.json index 96417b0..bf3e07c 100644 --- a/config_example.json +++ b/config_example.json @@ -1,6 +1,8 @@ { "pageImageWidth" : 748, - "minifyCSSandJS" : true, + "fullScreenImageWidth" : 4000, + "minifyJavaScript" : false, + "minifyCSS" : false, "createMdFilesIfMissing" : false, "contentPath" : "/path/to/content/folder", "outputPath" : "/path/to/output/folder") diff --git a/install.sh b/install.sh index 7b95153..5d673bc 100755 --- a/install.sh +++ b/install.sh @@ -1,14 +1,11 @@ #!/bin/bash # Install the required dependencies for CHGenerator -# Note: The following is only required if `minifyCSSandJS=True` -# is set in the generator configuration - -# Install the Javascript minifier +# Install the Javascript minifier (required if `minifyJavaScript = True`) # https://github.com/mishoo/UglifyJS npm install uglify-js -g -# Install the clean-css minifier +# Install the clean-css minifier (required if `minifyCSS = True`) # https://github.com/clean-css/clean-css-cli npm install clean-css-cli -g