aboutsummaryrefslogtreecommitdiff
path: root/compiler/app
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/app')
-rw-r--r--compiler/app/Main.hs15
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)
24import Data.Version (showVersion) 24import Data.Version (showVersion)
25import Data.Aeson (ToJSON) 25import Data.Aeson (ToJSON)
26import System.FilePath ((</>)) 26import System.FilePath ((</>))
27import System.Directory (canonicalizePath) 27import System.Directory (canonicalizePath, listDirectory)
28import System.Console.CmdArgs 28import System.Console.CmdArgs
29 29
30import Compiler 30import Compiler
31import Files (readDirectory, copyTo) 31import Files (readDirectory, copyTo, remove)
32 32
33 33
34data ViewerConfig = ViewerConfig 34data 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 ++ "/")