diff options
Diffstat (limited to 'compiler/app')
-rw-r--r-- | compiler/app/Main.hs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index 48e5644..e71e0db 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs | |||
@@ -21,6 +21,7 @@ module Main where | |||
21 | import GHC.Generics (Generic) | 21 | import GHC.Generics (Generic) |
22 | import Paths_ldgallery_compiler (version, getDataFileName) | 22 | import Paths_ldgallery_compiler (version, getDataFileName) |
23 | import Control.Monad (when) | 23 | import Control.Monad (when) |
24 | import Data.Functor ((<&>)) | ||
24 | import Data.Maybe (isJust) | 25 | import Data.Maybe (isJust) |
25 | import Data.Version (showVersion) | 26 | import Data.Version (showVersion) |
26 | import Data.Aeson (ToJSON) | 27 | import Data.Aeson (ToJSON) |
@@ -32,7 +33,7 @@ import Compiler | |||
32 | import Files (readDirectory, copyTo, remove) | 33 | import Files (readDirectory, copyTo, remove) |
33 | 34 | ||
34 | 35 | ||
35 | data ViewerConfig = ViewerConfig | 36 | newtype ViewerConfig = ViewerConfig |
36 | { galleryRoot :: String | 37 | { galleryRoot :: String |
37 | } deriving (Generic, Show, ToJSON) | 38 | } deriving (Generic, Show, ToJSON) |
38 | 39 | ||
@@ -42,7 +43,7 @@ data Options = Options | |||
42 | , outputDir :: FilePath | 43 | , outputDir :: FilePath |
43 | , outputIndex :: FilePath | 44 | , outputIndex :: FilePath |
44 | , galleryConfig :: FilePath | 45 | , galleryConfig :: FilePath |
45 | , rebuilAll :: Bool | 46 | , rebuildAll :: Bool |
46 | , cleanOutput :: Bool | 47 | , cleanOutput :: Bool |
47 | , withViewer :: Maybe FilePath | 48 | , withViewer :: Maybe FilePath |
48 | } deriving (Show, Data, Typeable) | 49 | } deriving (Show, Data, Typeable) |
@@ -73,7 +74,7 @@ options = Options | |||
73 | &= name "gallery-config" | 74 | &= name "gallery-config" |
74 | &= explicit | 75 | &= explicit |
75 | &= help "Gallery configuration file (default=<input-dir>/gallery.yaml)" | 76 | &= help "Gallery configuration file (default=<input-dir>/gallery.yaml)" |
76 | , rebuilAll = False | 77 | , rebuildAll = False |
77 | &= name "r" | 78 | &= name "r" |
78 | &= name "rebuild-all" | 79 | &= name "rebuild-all" |
79 | &= explicit | 80 | &= explicit |
@@ -92,7 +93,7 @@ options = Options | |||
92 | &= help "Deploy either the bundled or the given static web viewer to the output directory" | 93 | &= help "Deploy either the bundled or the given static web viewer to the output directory" |
93 | } | 94 | } |
94 | 95 | ||
95 | &= summary ("ldgallery v" ++ (showVersion version) ++ " - a static web gallery generator with tags") | 96 | &= summary ("ldgallery v" ++ showVersion version ++ " - a static web gallery generator with tags") |
96 | &= program "ldgallery" | 97 | &= program "ldgallery" |
97 | &= help "Compile a gallery" | 98 | &= help "Compile a gallery" |
98 | &= helpArg [explicit, name "h", name "help"] | 99 | &= helpArg [explicit, name "h", name "help"] |
@@ -130,7 +131,7 @@ main = | |||
130 | (galleryOutputDir opts) | 131 | (galleryOutputDir opts) |
131 | (outputIndex opts) | 132 | (outputIndex opts) |
132 | [outputDir opts] | 133 | [outputDir opts] |
133 | (rebuilAll opts) | 134 | (rebuildAll opts) |
134 | (cleanOutput opts) | 135 | (cleanOutput opts) |
135 | where | 136 | where |
136 | checkDistinctPaths :: FilePath -> FilePath -> IO () | 137 | checkDistinctPaths :: FilePath -> FilePath -> IO () |
@@ -146,7 +147,7 @@ main = | |||
146 | 147 | ||
147 | deployViewer :: FilePath -> Options -> IO () | 148 | deployViewer :: FilePath -> Options -> IO () |
148 | deployViewer distPath Options{outputDir, cleanOutput} = | 149 | deployViewer distPath Options{outputDir, cleanOutput} = |
149 | (when cleanOutput $ cleanViewerDir outputDir) | 150 | when cleanOutput (cleanViewerDir outputDir) |
150 | >> copyViewer distPath outputDir | 151 | >> copyViewer distPath outputDir |
151 | >> writeJSON (outputDir </> "config.json") viewerConfig | 152 | >> writeJSON (outputDir </> "config.json") viewerConfig |
152 | 153 | ||
@@ -154,8 +155,8 @@ main = | |||
154 | cleanViewerDir :: FilePath -> IO () | 155 | cleanViewerDir :: FilePath -> IO () |
155 | cleanViewerDir target = | 156 | cleanViewerDir target = |
156 | listDirectory target | 157 | listDirectory target |
157 | >>= return . filter (/= gallerySubdir) | 158 | <&> filter (/= gallerySubdir) |
158 | >>= mapM_ remove . map (target </>) | 159 | >>= mapM_ (remove . (target </>)) |
159 | 160 | ||
160 | copyViewer :: FilePath -> FilePath -> IO () | 161 | copyViewer :: FilePath -> FilePath -> IO () |
161 | copyViewer dist target = | 162 | copyViewer dist target = |