aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpacien2020-01-30 17:01:15 +0100
committerNotkea2020-01-30 17:17:59 +0100
commit15c806adec22239096a910b92b49fcfb964815bd (patch)
treead7123408a03bf40c40ebc2f5dc4e2382814ba08
parent3ef8c5a3e92dab3178d7892606149fedfaadc31f (diff)
downloadldgallery-15c806adec22239096a910b92b49fcfb964815bd.tar.gz
compiler: add flag for output dir cleanup
Making it explicit. GitHub: closes #62
-rw-r--r--compiler/app/Main.hs26
-rw-r--r--compiler/src/Compiler.hs10
-rw-r--r--ldgallery.1.md3
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
31 { inputDir :: String 31 { inputDir :: String
32 , outputDir :: String 32 , outputDir :: String
33 , rebuilAll :: Bool 33 , rebuilAll :: Bool
34 , cleanOutput :: Bool
34 , withViewer :: Bool 35 , withViewer :: Bool
35 } deriving (Show, Data, Typeable) 36 } deriving (Show, Data, Typeable)
36 37
@@ -53,6 +54,11 @@ options = Options
53 &= name "rebuild-all" 54 &= name "rebuild-all"
54 &= explicit 55 &= explicit
55 &= help "Invalidate cache and recompile everything" 56 &= help "Invalidate cache and recompile everything"
57 , cleanOutput = False
58 &= name "c"
59 &= name "clean-output"
60 &= explicit
61 &= help "Remove unnecessary files from the output directory"
56 , withViewer = False 62 , withViewer = False
57 &= name "w" 63 &= name "w"
58 &= name "with-viewer" 64 &= name "with-viewer"
@@ -71,10 +77,23 @@ main :: IO ()
71main = 77main =
72 do 78 do
73 opts <- cmdArgs options 79 opts <- cmdArgs options
74 compileGallery (inputDir opts) (galleryOutputDir "gallery" opts) (rebuilAll opts) 80
75 if (withViewer opts) then copyViewer (outputDir opts) else noop 81 buildGallery opts
82
83 if (withViewer opts) then
84 copyViewer (outputDir opts)
85 else
86 return ()
76 87
77 where 88 where
89 buildGallery :: Options -> IO ()
90 buildGallery opts =
91 compileGallery
92 (inputDir opts)
93 (galleryOutputDir "gallery" opts)
94 (rebuilAll opts)
95 (cleanOutput opts)
96
78 galleryOutputDir :: FilePath -> Options -> FilePath 97 galleryOutputDir :: FilePath -> Options -> FilePath
79 galleryOutputDir gallerySubdir opts = 98 galleryOutputDir gallerySubdir opts =
80 if withViewer opts then outputBase </> gallerySubdir else outputBase 99 if withViewer opts then outputBase </> gallerySubdir else outputBase
@@ -86,6 +105,3 @@ main =
86 >> getDataFileName "viewer" 105 >> getDataFileName "viewer"
87 >>= readDirectory 106 >>= readDirectory
88 >>= copyTo target 107 >>= copyTo target
89
90 noop :: IO ()
91 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 =
102 any (matchesFile (== indexFile) ||| matchesFile (== viewerMainFile)) items 102 any (matchesFile (== indexFile) ||| matchesFile (== viewerMainFile)) items
103 103
104 104
105compileGallery :: FilePath -> FilePath -> Bool -> IO () 105compileGallery :: FilePath -> FilePath -> Bool -> Bool -> IO ()
106compileGallery inputDirPath outputDirPath rebuildAll = 106compileGallery inputDirPath outputDirPath rebuildAll cleanOutput =
107 do 107 do
108 fullConfig <- readConfig inputGalleryConf 108 fullConfig <- readConfig inputGalleryConf
109 let config = compiler fullConfig 109 let config = compiler fullConfig
@@ -119,7 +119,11 @@ compileGallery inputDirPath outputDirPath rebuildAll =
119 let galleryBuilder = buildGalleryTree itemProc thumbnailProc (tagsFromDirectories config) 119 let galleryBuilder = buildGalleryTree itemProc thumbnailProc (tagsFromDirectories config)
120 resources <- galleryBuilder (galleryName config) inputTree 120 resources <- galleryBuilder (galleryName config) inputTree
121 121
122 galleryCleanupResourceDir resources outputDirPath 122 if cleanOutput then
123 galleryCleanupResourceDir resources outputDirPath
124 else
125 return ()
126
123 writeJSON outputIndex resources 127 writeJSON outputIndex resources
124 writeJSON outputViewerConf $ viewer fullConfig 128 writeJSON outputViewerConf $ viewer fullConfig
125 129
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:
33-r, \--rebuild-all 33-r, \--rebuild-all
34: Invalidate cache and recompile everything. 34: Invalidate cache and recompile everything.
35 35
36-c, \--clean-output
37: Remove unnecessary files from the output directory.
38
36-w, \--with-viewer 39-w, \--with-viewer
37: Include the static web viewer in the output. 40: Include the static web viewer in the output.
38 41