From 15c806adec22239096a910b92b49fcfb964815bd Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 30 Jan 2020 17:01:15 +0100 Subject: compiler: add flag for output dir cleanup Making it explicit. GitHub: closes #62 --- compiler/app/Main.hs | 26 +++++++++++++++++++++----- compiler/src/Compiler.hs | 10 +++++++--- ldgallery.1.md | 3 +++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index 1a42abf..4dd6660 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs @@ -31,6 +31,7 @@ data Options = Options { inputDir :: String , outputDir :: String , rebuilAll :: Bool + , cleanOutput :: Bool , withViewer :: Bool } deriving (Show, Data, Typeable) @@ -53,6 +54,11 @@ options = Options &= name "rebuild-all" &= explicit &= help "Invalidate cache and recompile everything" + , cleanOutput = False + &= name "c" + &= name "clean-output" + &= explicit + &= help "Remove unnecessary files from the output directory" , withViewer = False &= name "w" &= name "with-viewer" @@ -71,10 +77,23 @@ main :: IO () main = do opts <- cmdArgs options - compileGallery (inputDir opts) (galleryOutputDir "gallery" opts) (rebuilAll opts) - if (withViewer opts) then copyViewer (outputDir opts) else noop + + buildGallery opts + + if (withViewer opts) then + copyViewer (outputDir opts) + else + return () where + buildGallery :: Options -> IO () + buildGallery opts = + compileGallery + (inputDir opts) + (galleryOutputDir "gallery" opts) + (rebuilAll opts) + (cleanOutput opts) + galleryOutputDir :: FilePath -> Options -> FilePath galleryOutputDir gallerySubdir opts = if withViewer opts then outputBase gallerySubdir else outputBase @@ -86,6 +105,3 @@ main = >> getDataFileName "viewer" >>= readDirectory >>= copyTo target - - noop :: IO () - noop = return () diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs index 27598b7..fc40a76 100644 --- a/compiler/src/Compiler.hs +++ b/compiler/src/Compiler.hs @@ -102,8 +102,8 @@ galleryDirFilter config = any (matchesFile (== indexFile) ||| matchesFile (== viewerMainFile)) items -compileGallery :: FilePath -> FilePath -> Bool -> IO () -compileGallery inputDirPath outputDirPath rebuildAll = +compileGallery :: FilePath -> FilePath -> Bool -> Bool -> IO () +compileGallery inputDirPath outputDirPath rebuildAll cleanOutput = do fullConfig <- readConfig inputGalleryConf let config = compiler fullConfig @@ -119,7 +119,11 @@ compileGallery inputDirPath outputDirPath rebuildAll = let galleryBuilder = buildGalleryTree itemProc thumbnailProc (tagsFromDirectories config) resources <- galleryBuilder (galleryName config) inputTree - galleryCleanupResourceDir resources outputDirPath + if cleanOutput then + galleryCleanupResourceDir resources outputDirPath + else + return () + writeJSON outputIndex resources writeJSON outputViewerConf $ viewer fullConfig diff --git a/ldgallery.1.md b/ldgallery.1.md index febe2e2..c40a4ce 100644 --- a/ldgallery.1.md +++ b/ldgallery.1.md @@ -33,6 +33,9 @@ Available options are: -r, \--rebuild-all : Invalidate cache and recompile everything. +-c, \--clean-output +: Remove unnecessary files from the output directory. + -w, \--with-viewer : Include the static web viewer in the output. -- cgit v1.2.3