diff options
author | pacien | 2020-02-21 14:59:35 +0100 |
---|---|---|
committer | Notkea | 2020-02-25 15:17:29 +0100 |
commit | 9f5b07ccde8f54bb4d1905c8d51e69f762aed057 (patch) | |
tree | 0f3afc40131c27ec37fb92b5e22222adb627e4b0 /compiler | |
parent | 1ee205fd6cde9ee43330fb37fc408d0b6ef07bf1 (diff) | |
download | ldgallery-9f5b07ccde8f54bb4d1905c8d51e69f762aed057.tar.gz |
compiler: make --clean-output remove old viewer files
GitHub: closes #138
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/app/Main.hs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index 1229e88..404de4b 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs | |||
@@ -24,11 +24,11 @@ import Control.Monad (when) | |||
24 | import Data.Version (showVersion) | 24 | import Data.Version (showVersion) |
25 | import Data.Aeson (ToJSON) | 25 | import Data.Aeson (ToJSON) |
26 | import System.FilePath ((</>)) | 26 | import System.FilePath ((</>)) |
27 | import System.Directory (canonicalizePath) | 27 | import System.Directory (canonicalizePath, listDirectory) |
28 | import System.Console.CmdArgs | 28 | import System.Console.CmdArgs |
29 | 29 | ||
30 | import Compiler | 30 | import Compiler |
31 | import Files (readDirectory, copyTo) | 31 | import Files (readDirectory, copyTo, remove) |
32 | 32 | ||
33 | 33 | ||
34 | data ViewerConfig = ViewerConfig | 34 | data ViewerConfig = ViewerConfig |
@@ -95,12 +95,13 @@ main = | |||
95 | opts <- cmdArgs options | 95 | opts <- cmdArgs options |
96 | buildGallery opts | 96 | buildGallery opts |
97 | when (withViewer opts) $ do | 97 | when (withViewer opts) $ do |
98 | when (cleanOutput opts) $ cleanViewerDir (outputDir opts) | ||
98 | copyViewer (outputDir opts) | 99 | copyViewer (outputDir opts) |
99 | writeViewerConfig (outputDir opts </> "config.json") | 100 | writeViewerConfig (outputDir opts </> "config.json") |
100 | 101 | ||
101 | where | 102 | where |
102 | gallerySubdir :: String | 103 | gallerySubdir :: String |
103 | gallerySubdir = "gallery/" | 104 | gallerySubdir = "gallery" |
104 | 105 | ||
105 | buildGallery :: Options -> IO () | 106 | buildGallery :: Options -> IO () |
106 | buildGallery opts = | 107 | buildGallery opts = |
@@ -123,6 +124,12 @@ main = | |||
123 | if withViewer opts then outputBase </> gallerySubdir else outputBase | 124 | if withViewer opts then outputBase </> gallerySubdir else outputBase |
124 | where outputBase = outputDir opts | 125 | where outputBase = outputDir opts |
125 | 126 | ||
127 | cleanViewerDir :: FilePath -> IO () | ||
128 | cleanViewerDir target = | ||
129 | listDirectory target | ||
130 | >>= return . filter (/= gallerySubdir) | ||
131 | >>= mapM_ remove . map (target </>) | ||
132 | |||
126 | copyViewer :: FilePath -> IO () | 133 | copyViewer :: FilePath -> IO () |
127 | copyViewer target = | 134 | copyViewer target = |
128 | putStrLn "Copying viewer webapp" | 135 | putStrLn "Copying viewer webapp" |
@@ -131,4 +138,4 @@ main = | |||
131 | >>= copyTo target | 138 | >>= copyTo target |
132 | 139 | ||
133 | writeViewerConfig :: FilePath -> IO () | 140 | writeViewerConfig :: FilePath -> IO () |
134 | writeViewerConfig fileName = writeJSON fileName $ ViewerConfig gallerySubdir | 141 | writeViewerConfig fileName = writeJSON fileName $ ViewerConfig (gallerySubdir ++ "/") |