diff options
author | Zero~Informatique | 2020-01-31 02:15:26 +0100 |
---|---|---|
committer | Zero~Informatique | 2020-01-31 02:16:45 +0100 |
commit | 2157b66f3ea43137391939992cac4dc901a4ac4e (patch) | |
tree | 51f66cdada6a8e920ba80a3aae76393e0127d825 /compiler/app | |
parent | 293c2803794a5cc4f9a045d48ff28ae99beaa030 (diff) | |
download | ldgallery-2157b66f3ea43137391939992cac4dc901a4ac4e.tar.gz |
compiler: output viewer config.json
Write a file at the root of the viewer directory with some info about the
gallery root path and generation date time.
Diffstat (limited to 'compiler/app')
-rw-r--r-- | compiler/app/Main.hs | 30 |
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 | ||
19 | module Main where | 19 | module Main where |
20 | 20 | ||
21 | import GHC.Generics (Generic) | ||
21 | import Paths_ldgallery_compiler (version, getDataFileName) | 22 | import Paths_ldgallery_compiler (version, getDataFileName) |
22 | import Data.Version (showVersion) | 23 | import Data.Version (showVersion) |
24 | import Data.Int (Int64) | ||
25 | import Data.Aeson (ToJSON) | ||
26 | import Data.Time.Clock.System (getSystemTime, systemSeconds) | ||
23 | import System.FilePath ((</>)) | 27 | import System.FilePath ((</>)) |
24 | import System.Console.CmdArgs | 28 | import System.Console.CmdArgs |
25 | 29 | ||
@@ -27,6 +31,12 @@ import Compiler | |||
27 | import Files (readDirectory, copyTo) | 31 | import Files (readDirectory, copyTo) |
28 | 32 | ||
29 | 33 | ||
34 | data ViewerConfig = ViewerConfig | ||
35 | { galleryRoot :: String | ||
36 | , generationTimestamp :: Int64 | ||
37 | } deriving (Generic, Show, ToJSON) | ||
38 | |||
39 | |||
30 | data Options = Options | 40 | data Options = Options |
31 | { inputDir :: String | 41 | { inputDir :: String |
32 | , outputDir :: String | 42 | , outputDir :: String |
@@ -77,25 +87,27 @@ main :: IO () | |||
77 | main = | 87 | main = |
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 | ||