From 15c806adec22239096a910b92b49fcfb964815bd Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 30 Jan 2020 17:01:15 +0100 Subject: compiler: add flag for output dir cleanup Making it explicit. GitHub: closes #62 --- compiler/app/Main.hs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'compiler/app') diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index 1a42abf..4dd6660 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs @@ -31,6 +31,7 @@ data Options = Options { inputDir :: String , outputDir :: String , rebuilAll :: Bool + , cleanOutput :: Bool , withViewer :: Bool } deriving (Show, Data, Typeable) @@ -53,6 +54,11 @@ options = Options &= name "rebuild-all" &= explicit &= help "Invalidate cache and recompile everything" + , cleanOutput = False + &= name "c" + &= name "clean-output" + &= explicit + &= help "Remove unnecessary files from the output directory" , withViewer = False &= name "w" &= name "with-viewer" @@ -71,10 +77,23 @@ main :: IO () main = do opts <- cmdArgs options - compileGallery (inputDir opts) (galleryOutputDir "gallery" opts) (rebuilAll opts) - if (withViewer opts) then copyViewer (outputDir opts) else noop + + buildGallery opts + + if (withViewer opts) then + copyViewer (outputDir opts) + else + return () where + buildGallery :: Options -> IO () + buildGallery opts = + compileGallery + (inputDir opts) + (galleryOutputDir "gallery" opts) + (rebuilAll opts) + (cleanOutput opts) + galleryOutputDir :: FilePath -> Options -> FilePath galleryOutputDir gallerySubdir opts = if withViewer opts then outputBase gallerySubdir else outputBase @@ -86,6 +105,3 @@ main = >> getDataFileName "viewer" >>= readDirectory >>= copyTo target - - noop :: IO () - noop = return () -- cgit v1.2.3 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') 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 From c7c872291c2b053afc2c27f999f33b2cfb6c23f1 Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 3 Feb 2020 14:27:33 +0100 Subject: compiler: fix viewer output directory exclusion GitHub: closes #87 --- compiler/app/Main.hs | 1 + 1 file changed, 1 insertion(+) (limited to 'compiler/app') diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index e26055f..1864dee 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs @@ -103,6 +103,7 @@ main = compileGallery (inputDir opts) (galleryOutputDir opts) + [outputDir opts] (rebuilAll opts) (cleanOutput opts) -- cgit v1.2.3 From c22ea3de0fc5a42449b4bae80afa1a94c7afa41e Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 3 Feb 2020 15:10:58 +0100 Subject: compiler: reject input and output directories that coincide GitHub: closes #80 --- compiler/app/Main.hs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'compiler/app') diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index 1864dee..594a5b7 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs @@ -20,11 +20,13 @@ module Main where import GHC.Generics (Generic) import Paths_ldgallery_compiler (version, getDataFileName) +import Control.Monad (when) import Data.Version (showVersion) import Data.Int (Int64) import Data.Aeson (ToJSON) import Data.Time.Clock.System (getSystemTime, systemSeconds) import System.FilePath (()) +import System.Directory (canonicalizePath) import System.Console.CmdArgs import Compiler @@ -88,11 +90,9 @@ main = do opts <- cmdArgs options buildGallery opts - if (withViewer opts) then do + when (withViewer opts) $ do copyViewer (outputDir opts) writeViewerConfig (outputDir opts "config.json") - else - return () where gallerySubdir :: String @@ -100,12 +100,18 @@ main = buildGallery :: Options -> IO () buildGallery opts = - compileGallery - (inputDir opts) - (galleryOutputDir opts) - [outputDir opts] - (rebuilAll opts) - (cleanOutput opts) + checkDistinctPaths (inputDir opts) (outputDir opts) + >> compileGallery + (inputDir opts) + (galleryOutputDir opts) + [outputDir opts] + (rebuilAll opts) + (cleanOutput opts) + where + checkDistinctPaths a b = do + canonicalA <- canonicalizePath a + canonicalB <- canonicalizePath b + when (canonicalA == canonicalB) $ error "Input and output paths refer to the same location." galleryOutputDir :: Options -> FilePath galleryOutputDir opts = -- cgit v1.2.3 From bc4978e8060e106958498d78cb96b5103bf6f6ff Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 13 Feb 2020 21:51:18 +0100 Subject: compiler: remove timestamp field from generated viewer config As this field isn't used by the viewer anymore. GitHub: closes #124 --- compiler/app/Main.hs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'compiler/app') diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index 594a5b7..753f281 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs @@ -22,9 +22,7 @@ import GHC.Generics (Generic) import Paths_ldgallery_compiler (version, getDataFileName) import Control.Monad (when) import Data.Version (showVersion) -import Data.Int (Int64) import Data.Aeson (ToJSON) -import Data.Time.Clock.System (getSystemTime, systemSeconds) import System.FilePath (()) import System.Directory (canonicalizePath) import System.Console.CmdArgs @@ -35,7 +33,6 @@ import Files (readDirectory, copyTo) data ViewerConfig = ViewerConfig { galleryRoot :: String - , generationTimestamp :: Int64 } deriving (Generic, Show, ToJSON) @@ -126,7 +123,4 @@ main = >>= copyTo target writeViewerConfig :: FilePath -> IO () - writeViewerConfig fileName = - getSystemTime - >>= return . ViewerConfig gallerySubdir . systemSeconds - >>= writeJSON fileName + writeViewerConfig fileName = writeJSON fileName $ ViewerConfig gallerySubdir -- cgit v1.2.3 From ce0b7ec230703d239b3d77e09352c0b1d515d8f5 Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 21 Feb 2020 15:39:01 +0100 Subject: compiler: add gallery config file CLI argument GitHub: closes #136 --- compiler/app/Main.hs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'compiler/app') diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index 753f281..1229e88 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs @@ -37,8 +37,9 @@ data ViewerConfig = ViewerConfig data Options = Options - { inputDir :: String - , outputDir :: String + { inputDir :: FilePath + , outputDir :: FilePath + , galleryConfig :: FilePath , rebuilAll :: Bool , cleanOutput :: Bool , withViewer :: Bool @@ -58,6 +59,12 @@ options = Options &= name "output-dir" &= explicit &= help "Generated gallery output path (default=./out)" + , galleryConfig = "" + &= typFile + &= name "g" + &= name "gallery-config" + &= explicit + &= help "Gallery configuration file (default=$input-dir/gallery.yaml)" , rebuilAll = False &= name "r" &= name "rebuild-all" @@ -99,6 +106,7 @@ main = buildGallery opts = checkDistinctPaths (inputDir opts) (outputDir opts) >> compileGallery + (galleryConfig opts) (inputDir opts) (galleryOutputDir opts) [outputDir opts] -- cgit v1.2.3 From 9f5b07ccde8f54bb4d1905c8d51e69f762aed057 Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 21 Feb 2020 14:59:35 +0100 Subject: compiler: make --clean-output remove old viewer files GitHub: closes #138 --- compiler/app/Main.hs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'compiler/app') diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index 1229e88..404de4b 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs @@ -24,11 +24,11 @@ import Control.Monad (when) import Data.Version (showVersion) import Data.Aeson (ToJSON) import System.FilePath (()) -import System.Directory (canonicalizePath) +import System.Directory (canonicalizePath, listDirectory) import System.Console.CmdArgs import Compiler -import Files (readDirectory, copyTo) +import Files (readDirectory, copyTo, remove) data ViewerConfig = ViewerConfig @@ -95,12 +95,13 @@ main = opts <- cmdArgs options buildGallery opts when (withViewer opts) $ do + when (cleanOutput opts) $ cleanViewerDir (outputDir opts) copyViewer (outputDir opts) writeViewerConfig (outputDir opts "config.json") where gallerySubdir :: String - gallerySubdir = "gallery/" + gallerySubdir = "gallery" buildGallery :: Options -> IO () buildGallery opts = @@ -123,6 +124,12 @@ main = if withViewer opts then outputBase gallerySubdir else outputBase where outputBase = outputDir opts + cleanViewerDir :: FilePath -> IO () + cleanViewerDir target = + listDirectory target + >>= return . filter (/= gallerySubdir) + >>= mapM_ remove . map (target ) + copyViewer :: FilePath -> IO () copyViewer target = putStrLn "Copying viewer webapp" @@ -131,4 +138,4 @@ main = >>= copyTo target writeViewerConfig :: FilePath -> IO () - writeViewerConfig fileName = writeJSON fileName $ ViewerConfig gallerySubdir + writeViewerConfig fileName = writeJSON fileName $ ViewerConfig (gallerySubdir ++ "/") -- cgit v1.2.3 From 74e4a83ac7511086f45d2fa9880b7ae5728020bd Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 25 Feb 2020 20:19:54 +0100 Subject: compiler: add cli arg for output gallery index GitHub: closes #143 --- compiler/app/Main.hs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'compiler/app') diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index 404de4b..a4b6ae2 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs @@ -39,6 +39,7 @@ data ViewerConfig = ViewerConfig data Options = Options { inputDir :: FilePath , outputDir :: FilePath + , outputIndex :: FilePath , galleryConfig :: FilePath , rebuilAll :: Bool , cleanOutput :: Bool @@ -59,6 +60,12 @@ options = Options &= name "output-dir" &= explicit &= help "Generated gallery output path (default=./out)" + , outputIndex = "" + &= typFile + &= name "x" + &= name "output-index" + &= explicit + &= help "Generated gallery index output path (default=$output-dir/index.json)" , galleryConfig = "" &= typFile &= name "g" @@ -110,6 +117,7 @@ main = (galleryConfig opts) (inputDir opts) (galleryOutputDir opts) + (outputIndex opts) [outputDir opts] (rebuilAll opts) (cleanOutput opts) -- cgit v1.2.3 From d862c99d6ee74f25261c00fcfee3a6e551501f16 Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 27 Feb 2020 14:26:12 +0100 Subject: compiler: clarify dependent path documentation --- compiler/app/Main.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'compiler/app') diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index a4b6ae2..2fdaf3e 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs @@ -65,13 +65,13 @@ options = Options &= name "x" &= name "output-index" &= explicit - &= help "Generated gallery index output path (default=$output-dir/index.json)" + &= help "Generated gallery index output path (default=/index.json)" , galleryConfig = "" &= typFile &= name "g" &= name "gallery-config" &= explicit - &= help "Gallery configuration file (default=$input-dir/gallery.yaml)" + &= help "Gallery configuration file (default=/gallery.yaml)" , rebuilAll = False &= name "r" &= name "rebuild-all" -- cgit v1.2.3 From 4f1315cb9ff4a3dd78b90352bb517861bf2d59b7 Mon Sep 17 00:00:00 2001 From: pacien Date: Thu, 27 Feb 2020 17:13:58 +0100 Subject: compiler: allow explicit dist path for viewer deployment --- compiler/app/Main.hs | 69 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 27 deletions(-) (limited to 'compiler/app') diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs index 2fdaf3e..48e5644 100644 --- a/compiler/app/Main.hs +++ b/compiler/app/Main.hs @@ -21,6 +21,7 @@ module Main where import GHC.Generics (Generic) import Paths_ldgallery_compiler (version, getDataFileName) import Control.Monad (when) +import Data.Maybe (isJust) import Data.Version (showVersion) import Data.Aeson (ToJSON) import System.FilePath (()) @@ -43,7 +44,7 @@ data Options = Options , galleryConfig :: FilePath , rebuilAll :: Bool , cleanOutput :: Bool - , withViewer :: Bool + , withViewer :: Maybe FilePath } deriving (Show, Data, Typeable) options :: Options @@ -82,11 +83,13 @@ options = Options &= name "clean-output" &= explicit &= help "Remove unnecessary files from the output directory" - , withViewer = False + , withViewer = Nothing + &= typDir + &= opt ("" :: FilePath) &= name "w" &= name "with-viewer" &= explicit - &= help "Include the static web viewer in the output" + &= help "Deploy either the bundled or the given static web viewer to the output directory" } &= summary ("ldgallery v" ++ (showVersion version) ++ " - a static web gallery generator with tags") @@ -101,15 +104,23 @@ main = do opts <- cmdArgs options buildGallery opts - when (withViewer opts) $ do - when (cleanOutput opts) $ cleanViewerDir (outputDir opts) - copyViewer (outputDir opts) - writeViewerConfig (outputDir opts "config.json") + + when (isJust $ withViewer opts) $ do + viewerDist <- viewerDistPath $ withViewer opts + deployViewer viewerDist opts where gallerySubdir :: String gallerySubdir = "gallery" + viewerConfig :: ViewerConfig + viewerConfig = ViewerConfig (gallerySubdir ++ "/") + + viewerDistPath :: Maybe FilePath -> IO FilePath + viewerDistPath (Just "") = getDataFileName "viewer" + viewerDistPath (Just dist) = return dist + viewerDistPath Nothing = fail "No viewer distribution" + buildGallery :: Options -> IO () buildGallery opts = checkDistinctPaths (inputDir opts) (outputDir opts) @@ -122,28 +133,32 @@ main = (rebuilAll opts) (cleanOutput opts) where + checkDistinctPaths :: FilePath -> FilePath -> IO () checkDistinctPaths a b = do canonicalA <- canonicalizePath a canonicalB <- canonicalizePath b when (canonicalA == canonicalB) $ error "Input and output paths refer to the same location." - galleryOutputDir :: Options -> FilePath - galleryOutputDir opts = - if withViewer opts then outputBase gallerySubdir else outputBase - where outputBase = outputDir opts - - cleanViewerDir :: FilePath -> IO () - cleanViewerDir target = - listDirectory target - >>= return . filter (/= gallerySubdir) - >>= mapM_ remove . map (target ) - - copyViewer :: FilePath -> IO () - copyViewer target = - putStrLn "Copying viewer webapp" - >> getDataFileName "viewer" - >>= readDirectory - >>= copyTo target - - writeViewerConfig :: FilePath -> IO () - writeViewerConfig fileName = writeJSON fileName $ ViewerConfig (gallerySubdir ++ "/") + galleryOutputDir :: Options -> FilePath + galleryOutputDir Options{withViewer, outputDir} + | isJust withViewer = outputDir gallerySubdir + | otherwise = outputDir + + deployViewer :: FilePath -> Options -> IO () + deployViewer distPath Options{outputDir, cleanOutput} = + (when cleanOutput $ cleanViewerDir outputDir) + >> copyViewer distPath outputDir + >> writeJSON (outputDir "config.json") viewerConfig + + where + cleanViewerDir :: FilePath -> IO () + cleanViewerDir target = + listDirectory target + >>= return . filter (/= gallerySubdir) + >>= mapM_ remove . map (target ) + + copyViewer :: FilePath -> FilePath -> IO () + copyViewer dist target = + putStrLn "Copying viewer webapp" + >> readDirectory dist + >>= copyTo target -- cgit v1.2.3