From 2157b66f3ea43137391939992cac4dc901a4ac4e Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Fri, 31 Jan 2020 02:15:26 +0100 Subject: 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. --- compiler/app/Main.hs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'compiler/app/Main.hs') 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 @@ module Main where +import GHC.Generics (Generic) import Paths_ldgallery_compiler (version, getDataFileName) import Data.Version (showVersion) +import Data.Int (Int64) +import Data.Aeson (ToJSON) +import Data.Time.Clock.System (getSystemTime, systemSeconds) import System.FilePath (()) import System.Console.CmdArgs @@ -27,6 +31,12 @@ import Compiler import Files (readDirectory, copyTo) +data ViewerConfig = ViewerConfig + { galleryRoot :: String + , generationTimestamp :: Int64 + } deriving (Generic, Show, ToJSON) + + data Options = Options { inputDir :: String , outputDir :: String @@ -77,25 +87,27 @@ main :: IO () main = do opts <- cmdArgs options - buildGallery opts - - if (withViewer opts) then + if (withViewer opts) then do copyViewer (outputDir opts) + writeViewerConfig (outputDir opts "config.json") else return () where + gallerySubdir :: String + gallerySubdir = "gallery/" + buildGallery :: Options -> IO () buildGallery opts = compileGallery (inputDir opts) - (galleryOutputDir "gallery" opts) + (galleryOutputDir opts) (rebuilAll opts) (cleanOutput opts) - galleryOutputDir :: FilePath -> Options -> FilePath - galleryOutputDir gallerySubdir opts = + galleryOutputDir :: Options -> FilePath + galleryOutputDir opts = if withViewer opts then outputBase gallerySubdir else outputBase where outputBase = outputDir opts @@ -105,3 +117,9 @@ main = >> getDataFileName "viewer" >>= readDirectory >>= copyTo target + + writeViewerConfig :: FilePath -> IO () + writeViewerConfig fileName = + getSystemTime + >>= return . ViewerConfig gallerySubdir . systemSeconds + >>= writeJSON fileName -- cgit v1.2.3