aboutsummaryrefslogtreecommitdiff
path: root/compiler/app
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/app')
-rw-r--r--compiler/app/Main.hs30
1 files changed, 24 insertions, 6 deletions
diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs
index 4dd6660..e26055f 100644
--- a/compiler/app/Main.hs
+++ b/compiler/app/Main.hs
@@ -18,8 +18,12 @@
18 18
19module Main where 19module Main where
20 20
21import GHC.Generics (Generic)
21import Paths_ldgallery_compiler (version, getDataFileName) 22import Paths_ldgallery_compiler (version, getDataFileName)
22import Data.Version (showVersion) 23import Data.Version (showVersion)
24import Data.Int (Int64)
25import Data.Aeson (ToJSON)
26import Data.Time.Clock.System (getSystemTime, systemSeconds)
23import System.FilePath ((</>)) 27import System.FilePath ((</>))
24import System.Console.CmdArgs 28import System.Console.CmdArgs
25 29
@@ -27,6 +31,12 @@ import Compiler
27import Files (readDirectory, copyTo) 31import Files (readDirectory, copyTo)
28 32
29 33
34data ViewerConfig = ViewerConfig
35 { galleryRoot :: String
36 , generationTimestamp :: Int64
37 } deriving (Generic, Show, ToJSON)
38
39
30data Options = Options 40data Options = Options
31 { inputDir :: String 41 { inputDir :: String
32 , outputDir :: String 42 , outputDir :: String
@@ -77,25 +87,27 @@ main :: IO ()
77main = 87main =
78 do 88 do
79 opts <- cmdArgs options 89 opts <- cmdArgs options
80
81 buildGallery opts 90 buildGallery opts
82 91 if (withViewer opts) then do
83 if (withViewer opts) then
84 copyViewer (outputDir opts) 92 copyViewer (outputDir opts)
93 writeViewerConfig (outputDir opts </> "config.json")
85 else 94 else
86 return () 95 return ()
87 96
88 where 97 where
98 gallerySubdir :: String
99 gallerySubdir = "gallery/"
100
89 buildGallery :: Options -> IO () 101 buildGallery :: Options -> IO ()
90 buildGallery opts = 102 buildGallery opts =
91 compileGallery 103 compileGallery
92 (inputDir opts) 104 (inputDir opts)
93 (galleryOutputDir "gallery" opts) 105 (galleryOutputDir opts)
94 (rebuilAll opts) 106 (rebuilAll opts)
95 (cleanOutput opts) 107 (cleanOutput opts)
96 108
97 galleryOutputDir :: FilePath -> Options -> FilePath 109 galleryOutputDir :: Options -> FilePath
98 galleryOutputDir gallerySubdir opts = 110 galleryOutputDir opts =
99 if withViewer opts then outputBase </> gallerySubdir else outputBase 111 if withViewer opts then outputBase </> gallerySubdir else outputBase
100 where outputBase = outputDir opts 112 where outputBase = outputDir opts
101 113
@@ -105,3 +117,9 @@ main =
105 >> getDataFileName "viewer" 117 >> getDataFileName "viewer"
106 >>= readDirectory 118 >>= readDirectory
107 >>= copyTo target 119 >>= copyTo target
120
121 writeViewerConfig :: FilePath -> IO ()
122 writeViewerConfig fileName =
123 getSystemTime
124 >>= return . ViewerConfig gallerySubdir . systemSeconds
125 >>= writeJSON fileName