aboutsummaryrefslogtreecommitdiff
path: root/compiler/app/Main.hs
diff options
context:
space:
mode:
authorpacien2022-09-04 18:18:27 +0200
committerpacien2022-09-04 18:18:27 +0200
commit11bbbae2850b9c45da697a8ed9626495a50a38c0 (patch)
treeff2713118f8b45d36905bfea2933f08d8e70066d /compiler/app/Main.hs
parente93f7b1eb84c083d67567115284c0002a3a7d5fc (diff)
parent8349be992b46b77dee921f484cfbff8b758ff756 (diff)
downloadldgallery-11bbbae2850b9c45da697a8ed9626495a50a38c0.tar.gz
Merge branch 'develop': release v2.1v2.1
GitHub: related to #315
Diffstat (limited to 'compiler/app/Main.hs')
-rw-r--r--compiler/app/Main.hs32
1 files changed, 15 insertions, 17 deletions
diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs
index e71e0db..3e6f254 100644
--- a/compiler/app/Main.hs
+++ b/compiler/app/Main.hs
@@ -1,7 +1,7 @@
1-- ldgallery - A static generator which turns a collection of tagged 1-- ldgallery - A static generator which turns a collection of tagged
2-- pictures into a searchable web gallery. 2-- pictures into a searchable web gallery.
3-- 3--
4-- Copyright (C) 2019-2020 Pacien TRAN-GIRARD 4-- Copyright (C) 2019-2021 Pacien TRAN-GIRARD
5-- 5--
6-- This program is free software: you can redistribute it and/or modify 6-- This program is free software: you can redistribute it and/or modify
7-- it under the terms of the GNU Affero General Public License as 7-- it under the terms of the GNU Affero General Public License as
@@ -19,7 +19,7 @@
19module Main where 19module Main where
20 20
21import GHC.Generics (Generic) 21import GHC.Generics (Generic)
22import Paths_ldgallery_compiler (version, getDataFileName) 22import Paths_ldgallery_compiler (version)
23import Control.Monad (when) 23import Control.Monad (when)
24import Data.Functor ((<&>)) 24import Data.Functor ((<&>))
25import Data.Maybe (isJust) 25import Data.Maybe (isJust)
@@ -31,7 +31,7 @@ import System.Console.CmdArgs
31 31
32import Compiler 32import Compiler
33import Files (readDirectory, copyTo, remove) 33import Files (readDirectory, copyTo, remove)
34 34import ViewerDist (viewerDistPath)
35 35
36newtype ViewerConfig = ViewerConfig 36newtype ViewerConfig = ViewerConfig
37 { galleryRoot :: String 37 { galleryRoot :: String
@@ -94,6 +94,7 @@ options = Options
94 } 94 }
95 95
96 &= summary ("ldgallery v" ++ showVersion version ++ " - a static web gallery generator with tags") 96 &= summary ("ldgallery v" ++ showVersion version ++ " - a static web gallery generator with tags")
97 &= details ["This software is distributed under the terms of the GNU Affero General Public License v3.0."]
97 &= program "ldgallery" 98 &= program "ldgallery"
98 &= help "Compile a gallery" 99 &= help "Compile a gallery"
99 &= helpArg [explicit, name "h", name "help"] 100 &= helpArg [explicit, name "h", name "help"]
@@ -105,10 +106,7 @@ main =
105 do 106 do
106 opts <- cmdArgs options 107 opts <- cmdArgs options
107 buildGallery opts 108 buildGallery opts
108 109 deployViewer opts
109 when (isJust $ withViewer opts) $ do
110 viewerDist <- viewerDistPath $ withViewer opts
111 deployViewer viewerDist opts
112 110
113 where 111 where
114 gallerySubdir :: String 112 gallerySubdir :: String
@@ -117,11 +115,6 @@ main =
117 viewerConfig :: ViewerConfig 115 viewerConfig :: ViewerConfig
118 viewerConfig = ViewerConfig (gallerySubdir ++ "/") 116 viewerConfig = ViewerConfig (gallerySubdir ++ "/")
119 117
120 viewerDistPath :: Maybe FilePath -> IO FilePath
121 viewerDistPath (Just "") = getDataFileName "viewer"
122 viewerDistPath (Just dist) = return dist
123 viewerDistPath Nothing = fail "No viewer distribution"
124
125 buildGallery :: Options -> IO () 118 buildGallery :: Options -> IO ()
126 buildGallery opts = 119 buildGallery opts =
127 checkDistinctPaths (inputDir opts) (outputDir opts) 120 checkDistinctPaths (inputDir opts) (outputDir opts)
@@ -145,10 +138,11 @@ main =
145 | isJust withViewer = outputDir </> gallerySubdir 138 | isJust withViewer = outputDir </> gallerySubdir
146 | otherwise = outputDir 139 | otherwise = outputDir
147 140
148 deployViewer :: FilePath -> Options -> IO () 141 deployViewer :: Options -> IO ()
149 deployViewer distPath Options{outputDir, cleanOutput} = 142 deployViewer Options{withViewer = Nothing} = pure ()
143 deployViewer Options{withViewer = Just viewerPath, outputDir, cleanOutput} =
150 when cleanOutput (cleanViewerDir outputDir) 144 when cleanOutput (cleanViewerDir outputDir)
151 >> copyViewer distPath outputDir 145 >> viewerDistOr viewerPath >>= deployTo outputDir
152 >> writeJSON (outputDir </> "config.json") viewerConfig 146 >> writeJSON (outputDir </> "config.json") viewerConfig
153 147
154 where 148 where
@@ -158,8 +152,12 @@ main =
158 <&> filter (/= gallerySubdir) 152 <&> filter (/= gallerySubdir)
159 >>= mapM_ (remove . (target </>)) 153 >>= mapM_ (remove . (target </>))
160 154
161 copyViewer :: FilePath -> FilePath -> IO () 155 viewerDistOr :: FilePath -> IO FilePath
162 copyViewer dist target = 156 viewerDistOr "" = viewerDistPath
157 viewerDistOr custom = pure custom
158
159 deployTo :: FilePath -> FilePath -> IO ()
160 deployTo target dist =
163 putStrLn "Copying viewer webapp" 161 putStrLn "Copying viewer webapp"
164 >> readDirectory dist 162 >> readDirectory dist
165 >>= copyTo target 163 >>= copyTo target