aboutsummaryrefslogtreecommitdiff
path: root/compiler/app
diff options
context:
space:
mode:
authorpacien2019-12-31 06:58:53 +0100
committerpacien2019-12-31 06:58:53 +0100
commit641ea85d4da795cb2c67d9777cb3db3dfede1d8b (patch)
tree6f6df263e879b64d55038ef400c79b089511fe55 /compiler/app
parent7ef9f09c0f3be1cd5e1f38c9abc845abc9ed3639 (diff)
downloadldgallery-641ea85d4da795cb2c67d9777cb3db3dfede1d8b.tar.gz
compiler: add option to include static web app in the output
GitHub: closes #6
Diffstat (limited to 'compiler/app')
-rw-r--r--compiler/app/Main.hs54
1 files changed, 45 insertions, 9 deletions
diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs
index 1773073..24d8aad 100644
--- a/compiler/app/Main.hs
+++ b/compiler/app/Main.hs
@@ -22,37 +22,73 @@
22 22
23module Main where 23module Main where
24 24
25import Paths_ldgallery_compiler (version) 25import Paths_ldgallery_compiler (version, getDataFileName)
26import Data.Version (showVersion) 26import Data.Version (showVersion)
27import System.FilePath ((</>))
27import System.Console.CmdArgs 28import System.Console.CmdArgs
29
28import Compiler 30import Compiler
31import Files (readDirectory, copyTo)
29 32
30 33
31data Options = Options 34data Options = Options
32 { inputDir :: String 35 { inputDir :: String
33 , outputDir :: String 36 , outputDir :: String
34 , rebuild :: Bool 37 , rebuilAll :: Bool
38 , withViewer :: Bool
35 } deriving (Show, Data, Typeable) 39 } deriving (Show, Data, Typeable)
36 40
37options = Options 41options = Options
38 { inputDir = "./" 42 { inputDir = "./"
39 &= typDir 43 &= typDir
44 &= explicit
45 &= name "i"
46 &= name "input-dir"
40 &= help "Gallery source directory (default=./)" 47 &= help "Gallery source directory (default=./)"
41 , outputDir = "./out" 48 , outputDir = "./out"
42 &= typDir 49 &= typDir
50 &= explicit
51 &= name "o"
52 &= name "output-dir"
43 &= help "Generated gallery output path (default=./out)" 53 &= help "Generated gallery output path (default=./out)"
44 , rebuild = False 54 , rebuilAll = False
55 &= explicit
56 &= name "r"
57 &= name "rebuild-all"
45 &= help "Invalidate cache and recompile everything" 58 &= help "Invalidate cache and recompile everything"
59 , withViewer = False
60 &= explicit
61 &= name "w"
62 &= name "with-viewer"
63 &= help "Include the static web viewer in the output"
46 } 64 }
47 &= summary ("ldgallery v" ++ (showVersion version) ++ " - a static gallery generator with tags") 65
48 &= program "ldgallery" 66 &= summary ("ldgallery v" ++ (showVersion version) ++ " - a static gallery generator with tags")
49 &= help "Compile a gallery" 67 &= program "ldgallery"
50 &= helpArg [explicit, name "h", name "help"] 68 &= help "Compile a gallery"
51 &= versionArg [explicit, name "v", name "version"] 69 &= helpArg [explicit, name "h", name "help"]
70 &= versionArg [explicit, name "version"]
52 71
53 72
54main :: IO () 73main :: IO ()
55main = 74main =
56 do 75 do
57 opts <- cmdArgs options 76 opts <- cmdArgs options
58 compileGallery (inputDir opts) (outputDir opts) (rebuild opts) 77 compileGallery (inputDir opts) (galleryOutputDir "gallery" opts) (rebuilAll opts)
78 if (withViewer opts) then copyViewer (outputDir opts) else noop
79
80 where
81 galleryOutputDir :: FilePath -> Options -> FilePath
82 galleryOutputDir gallerySubdir opts =
83 if withViewer opts then outputBase </> gallerySubdir else outputBase
84 where outputBase = outputDir opts
85
86 copyViewer :: FilePath -> IO ()
87 copyViewer target =
88 putStrLn "Copying viewer webapp"
89 >> getDataFileName "viewer"
90 >>= readDirectory
91 >>= copyTo target
92
93 noop :: IO ()
94 noop = return ()