aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpacien2019-12-31 06:58:53 +0100
committerpacien2019-12-31 06:58:53 +0100
commit641ea85d4da795cb2c67d9777cb3db3dfede1d8b (patch)
tree6f6df263e879b64d55038ef400c79b089511fe55
parent7ef9f09c0f3be1cd5e1f38c9abc845abc9ed3639 (diff)
downloadldgallery-641ea85d4da795cb2c67d9777cb3db3dfede1d8b.tar.gz
compiler: add option to include static web app in the output
GitHub: closes #6
-rw-r--r--compiler/app/Main.hs54
-rw-r--r--compiler/data/.gitignore1
-rw-r--r--compiler/data/readme.md1
-rw-r--r--compiler/package.yaml3
-rw-r--r--compiler/src/Files.hs17
5 files changed, 65 insertions, 11 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 ()
diff --git a/compiler/data/.gitignore b/compiler/data/.gitignore
new file mode 100644
index 0000000..dd4395c
--- /dev/null
+++ b/compiler/data/.gitignore
@@ -0,0 +1 @@
viewer
diff --git a/compiler/data/readme.md b/compiler/data/readme.md
new file mode 100644
index 0000000..9aded74
--- /dev/null
+++ b/compiler/data/readme.md
@@ -0,0 +1 @@
Link `../../viewer/dist` to `./viewer` for full distribution.
diff --git a/compiler/package.yaml b/compiler/package.yaml
index 90c4ea5..0b03887 100644
--- a/compiler/package.yaml
+++ b/compiler/package.yaml
@@ -27,6 +27,9 @@ dependencies:
27- JuicyPixels-extra 27- JuicyPixels-extra
28- parallel-io 28- parallel-io
29 29
30data-dir: data
31data-files: ["**/*"]
32
30library: 33library:
31 source-dirs: src 34 source-dirs: src
32 35
diff --git a/compiler/src/Files.hs b/compiler/src/Files.hs
index a6649c8..a658ded 100644
--- a/compiler/src/Files.hs
+++ b/compiler/src/Files.hs
@@ -19,6 +19,7 @@
19{-# LANGUAGE 19{-# LANGUAGE
20 DuplicateRecordFields 20 DuplicateRecordFields
21 , DeriveGeneric 21 , DeriveGeneric
22 , NamedFieldPuns
22#-} 23#-}
23 24
24module Files 25module Files
@@ -27,7 +28,8 @@ module Files
27 , fileName, maybeFileName, subPaths, pathLength 28 , fileName, maybeFileName, subPaths, pathLength
28 , localPath, webPath 29 , localPath, webPath
29 , FSNode(..), AnchoredFSNode(..) 30 , FSNode(..), AnchoredFSNode(..)
30 , nodePath, nodeName, isHidden, flattenDir, filterDir, readDirectory 31 , nodePath, nodeName, isHidden, flattenDir, filterDir
32 , readDirectory, copyTo
31 , ensureParentDir, remove, isOutdated 33 , ensureParentDir, remove, isOutdated
32 ) where 34 ) where
33 35
@@ -46,7 +48,8 @@ import System.Directory
46 , getModificationTime 48 , getModificationTime
47 , listDirectory 49 , listDirectory
48 , createDirectoryIfMissing 50 , createDirectoryIfMissing
49 , removePathForcibly ) 51 , removePathForcibly
52 , copyFile )
50 53
51import qualified System.FilePath 54import qualified System.FilePath
52import qualified System.FilePath.Posix 55import qualified System.FilePath.Posix
@@ -146,6 +149,16 @@ readDirectory root = mkNode (Path []) >>= return . AnchoredFSNode root
146 >>= mapM (mkNode . ((</) path)) 149 >>= mapM (mkNode . ((</) path))
147 >>= return . Dir path 150 >>= return . Dir path
148 151
152copyTo :: FilePath -> AnchoredFSNode -> IO ()
153copyTo target AnchoredFSNode{anchor, root} = copyNode root
154 where
155 copyNode :: FSNode -> IO ()
156 copyNode (File path) =
157 copyFile (localPath $ anchor /> path) (localPath $ target /> path)
158
159 copyNode (Dir path items) =
160 createDirectoryIfMissing True (localPath $ target /> path)
161 >> mapM_ copyNode items
149 162
150ensureParentDir :: (FileName -> a -> IO b) -> FileName -> a -> IO b 163ensureParentDir :: (FileName -> a -> IO b) -> FileName -> a -> IO b
151ensureParentDir writer filePath a = 164ensureParentDir writer filePath a =