aboutsummaryrefslogtreecommitdiff
path: root/compiler/app/Main.hs
diff options
context:
space:
mode:
authorNotkea2020-01-10 22:31:47 +0100
committerGitHub2020-01-10 22:31:47 +0100
commit7042ffc06326fa8ffe70f5a59747709250166c16 (patch)
treedbfc7567bd106e03a47b499d2a07cecb6b8d6305 /compiler/app/Main.hs
parentc9264b0a0a7e1cb92ef7d9a391cee2c94376cff3 (diff)
parent27b51018525dbb7a6edb3073819d82245387ddd3 (diff)
downloadldgallery-7042ffc06326fa8ffe70f5a59747709250166c16.tar.gz
Merge pull request #34 from pacien/develop
first working prototype
Diffstat (limited to 'compiler/app/Main.hs')
-rw-r--r--compiler/app/Main.hs91
1 files changed, 91 insertions, 0 deletions
diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs
new file mode 100644
index 0000000..1a42abf
--- /dev/null
+++ b/compiler/app/Main.hs
@@ -0,0 +1,91 @@
1-- ldgallery - A static generator which turns a collection of tagged
2-- pictures into a searchable web gallery.
3--
4-- Copyright (C) 2019-2020 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
19module Main where
20
21import Paths_ldgallery_compiler (version, getDataFileName)
22import Data.Version (showVersion)
23import System.FilePath ((</>))
24import System.Console.CmdArgs
25
26import Compiler
27import Files (readDirectory, copyTo)
28
29
30data Options = Options
31 { inputDir :: String
32 , outputDir :: String
33 , rebuilAll :: Bool
34 , withViewer :: Bool
35 } deriving (Show, Data, Typeable)
36
37options :: Options
38options = Options
39 { inputDir = "./"
40 &= typDir
41 &= name "i"
42 &= name "input-dir"
43 &= explicit
44 &= help "Gallery source directory (default=./)"
45 , outputDir = "./out"
46 &= typDir
47 &= name "o"
48 &= name "output-dir"
49 &= explicit
50 &= help "Generated gallery output path (default=./out)"
51 , rebuilAll = False
52 &= name "r"
53 &= name "rebuild-all"
54 &= explicit
55 &= help "Invalidate cache and recompile everything"
56 , withViewer = False
57 &= name "w"
58 &= name "with-viewer"
59 &= explicit
60 &= help "Include the static web viewer in the output"
61 }
62
63 &= summary ("ldgallery v" ++ (showVersion version) ++ " - a static web gallery generator with tags")
64 &= program "ldgallery"
65 &= help "Compile a gallery"
66 &= helpArg [explicit, name "h", name "help"]
67 &= versionArg [explicit, name "version"]
68
69
70main :: IO ()
71main =
72 do
73 opts <- cmdArgs options
74 compileGallery (inputDir opts) (galleryOutputDir "gallery" opts) (rebuilAll opts)
75 if (withViewer opts) then copyViewer (outputDir opts) else noop
76
77 where
78 galleryOutputDir :: FilePath -> Options -> FilePath
79 galleryOutputDir gallerySubdir opts =
80 if withViewer opts then outputBase </> gallerySubdir else outputBase
81 where outputBase = outputDir opts
82
83 copyViewer :: FilePath -> IO ()
84 copyViewer target =
85 putStrLn "Copying viewer webapp"
86 >> getDataFileName "viewer"
87 >>= readDirectory
88 >>= copyTo target
89
90 noop :: IO ()
91 noop = return ()