aboutsummaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorOzoneGrif2020-01-31 02:26:12 +0100
committerGitHub2020-01-31 02:26:12 +0100
commitd94b987463169b254ab69a79ddb58e5beccb0941 (patch)
tree51f66cdada6a8e920ba80a3aae76393e0127d825 /compiler
parent15c806adec22239096a910b92b49fcfb964815bd (diff)
parent2157b66f3ea43137391939992cac4dc901a4ac4e (diff)
downloadldgallery-d94b987463169b254ab69a79ddb58e5beccb0941.tar.gz
Merge pull request #65 from pacien/oz-viewer
viewer improvements
Diffstat (limited to 'compiler')
-rw-r--r--compiler/app/Main.hs30
-rw-r--r--compiler/data/viewer/readme.md2
-rw-r--r--compiler/src/Compiler.hs1
3 files changed, 27 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
diff --git a/compiler/data/viewer/readme.md b/compiler/data/viewer/readme.md
new file mode 100644
index 0000000..5786878
--- /dev/null
+++ b/compiler/data/viewer/readme.md
@@ -0,0 +1,2 @@
1Missing viewer distribution.
2Copy the files in "/viewer/dist/*" here, then rebuild the compiler.
diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs
index fc40a76..8819ffc 100644
--- a/compiler/src/Compiler.hs
+++ b/compiler/src/Compiler.hs
@@ -18,6 +18,7 @@
18 18
19module Compiler 19module Compiler
20 ( compileGallery 20 ( compileGallery
21 , writeJSON
21 ) where 22 ) where
22 23
23 24