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 ++++++++++++++++++++++++------ compiler/data/viewer/readme.md | 2 ++ compiler/src/Compiler.hs | 1 + viewer/public/config.json | 4 ++++ 4 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 compiler/data/viewer/readme.md create mode 100644 viewer/public/config.json 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 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 @@ +Missing viewer distribution. +Copy 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 @@ module Compiler ( compileGallery + , writeJSON ) where diff --git a/viewer/public/config.json b/viewer/public/config.json new file mode 100644 index 0000000..7023edb --- /dev/null +++ b/viewer/public/config.json @@ -0,0 +1,4 @@ +{ + "generationTimestamp": 0, + "galleryRoot": "gallery/" +} \ No newline at end of file -- cgit v1.2.3