aboutsummaryrefslogtreecommitdiff
path: root/compiler/app
diff options
context:
space:
mode:
authorzeroinformatique2021-06-29 17:23:22 +0200
committerGitHub2021-06-29 17:23:22 +0200
commit1cf6dd4243a72935d382d62bb2a79ff13186e70d (patch)
tree8f6447aa8dc0802eea625fd61fc8ac895e421b4f /compiler/app
parent622af23bb3ce8d6dc8dc1d658cb7f01bc905ef2c (diff)
parent083f0658399afc206ea0751415d54a50d2aa4fe9 (diff)
downloadldgallery-1cf6dd4243a72935d382d62bb2a79ff13186e70d.tar.gz
Merge pull request #294 from ldgallery/pacien-20210629-portable-viewer-dist
compiler: portable viewer dist
Diffstat (limited to 'compiler/app')
-rw-r--r--compiler/app/Main.hs29
-rw-r--r--compiler/app/ViewerDist.hs39
2 files changed, 52 insertions, 16 deletions
diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs
index dc97b38..3e6f254 100644
--- a/compiler/app/Main.hs
+++ b/compiler/app/Main.hs
@@ -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
@@ -106,10 +106,7 @@ main =
106 do 106 do
107 opts <- cmdArgs options 107 opts <- cmdArgs options
108 buildGallery opts 108 buildGallery opts
109 109 deployViewer opts
110 when (isJust $ withViewer opts) $ do
111 viewerDist <- viewerDistPath $ withViewer opts
112 deployViewer viewerDist opts
113 110
114 where 111 where
115 gallerySubdir :: String 112 gallerySubdir :: String
@@ -118,11 +115,6 @@ main =
118 viewerConfig :: ViewerConfig 115 viewerConfig :: ViewerConfig
119 viewerConfig = ViewerConfig (gallerySubdir ++ "/") 116 viewerConfig = ViewerConfig (gallerySubdir ++ "/")
120 117
121 viewerDistPath :: Maybe FilePath -> IO FilePath
122 viewerDistPath (Just "") = getDataFileName "viewer"
123 viewerDistPath (Just dist) = return dist
124 viewerDistPath Nothing = fail "No viewer distribution"
125
126 buildGallery :: Options -> IO () 118 buildGallery :: Options -> IO ()
127 buildGallery opts = 119 buildGallery opts =
128 checkDistinctPaths (inputDir opts) (outputDir opts) 120 checkDistinctPaths (inputDir opts) (outputDir opts)
@@ -146,10 +138,11 @@ main =
146 | isJust withViewer = outputDir </> gallerySubdir 138 | isJust withViewer = outputDir </> gallerySubdir
147 | otherwise = outputDir 139 | otherwise = outputDir
148 140
149 deployViewer :: FilePath -> Options -> IO () 141 deployViewer :: Options -> IO ()
150 deployViewer distPath Options{outputDir, cleanOutput} = 142 deployViewer Options{withViewer = Nothing} = pure ()
143 deployViewer Options{withViewer = Just viewerPath, outputDir, cleanOutput} =
151 when cleanOutput (cleanViewerDir outputDir) 144 when cleanOutput (cleanViewerDir outputDir)
152 >> copyViewer distPath outputDir 145 >> viewerDistOr viewerPath >>= deployTo outputDir
153 >> writeJSON (outputDir </> "config.json") viewerConfig 146 >> writeJSON (outputDir </> "config.json") viewerConfig
154 147
155 where 148 where
@@ -159,8 +152,12 @@ main =
159 <&> filter (/= gallerySubdir) 152 <&> filter (/= gallerySubdir)
160 >>= mapM_ (remove . (target </>)) 153 >>= mapM_ (remove . (target </>))
161 154
162 copyViewer :: FilePath -> FilePath -> IO () 155 viewerDistOr :: FilePath -> IO FilePath
163 copyViewer dist target = 156 viewerDistOr "" = viewerDistPath
157 viewerDistOr custom = pure custom
158
159 deployTo :: FilePath -> FilePath -> IO ()
160 deployTo target dist =
164 putStrLn "Copying viewer webapp" 161 putStrLn "Copying viewer webapp"
165 >> readDirectory dist 162 >> readDirectory dist
166 >>= copyTo target 163 >>= copyTo target
diff --git a/compiler/app/ViewerDist.hs b/compiler/app/ViewerDist.hs
new file mode 100644
index 0000000..2b80ffc
--- /dev/null
+++ b/compiler/app/ViewerDist.hs
@@ -0,0 +1,39 @@
1-- ldgallery - A static generator which turns a collection of tagged
2-- pictures into a searchable web gallery.
3--
4-- Copyright (C) 2021 Pacien TRAN-GIRARD
5--
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
8-- published by the Free Software Foundation, either version 3 of the
9-- License, or (at your option) any later version.
10--
11-- This program is distributed in the hope that it will be useful,
12-- but WITHOUT ANY WARRANTY; without even the implied warranty of
13-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-- GNU Affero General Public License for more details.
15--
16-- You should have received a copy of the GNU Affero General Public License
17-- along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19{-# LANGUAGE CPP #-}
20
21module ViewerDist where
22
23#ifndef FLAG_PORTABLE
24
25import Paths_ldgallery_compiler (getDataFileName)
26
27viewerDistPath = getDataFileName "viewer"
28
29#else
30
31import Data.Functor ((<&>))
32import System.FilePath (takeDirectory, (</>))
33import System.Environment (getExecutablePath)
34
35viewerDistPath = fmap takeDirectory getExecutablePath <&> (</> "viewer")
36
37#endif
38
39viewerDistPath :: IO FilePath