aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/Lib.hs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/src/Lib.hs')
-rw-r--r--compiler/src/Lib.hs32
1 files changed, 19 insertions, 13 deletions
diff --git a/compiler/src/Lib.hs b/compiler/src/Lib.hs
index 2068b4a..643e5f6 100644
--- a/compiler/src/Lib.hs
+++ b/compiler/src/Lib.hs
@@ -26,15 +26,17 @@ module Lib
26 26
27import GHC.Generics (Generic) 27import GHC.Generics (Generic)
28import Data.Function ((&)) 28import Data.Function ((&))
29import System.Directory (createDirectoryIfMissing) 29import Data.Ord (comparing)
30import Data.List (sortBy, length)
31import System.Directory (createDirectoryIfMissing, removePathForcibly)
30import System.FilePath (dropFileName, (</>)) 32import System.FilePath (dropFileName, (</>))
31 33
32import Data.Aeson (ToJSON, FromJSON) 34import Data.Aeson (ToJSON, FromJSON)
33import qualified Data.Aeson as JSON 35import qualified Data.Aeson as JSON
34 36
35import Files (FileName, readDirectory) 37import Files (FileName, readDirectory, localPath, flattenDir, root, (/>))
36import Input (decodeYamlFile, readInputTree) 38import Input (decodeYamlFile, readInputTree)
37import Resource (buildResourceTree) 39import Resource (ResourceTree, buildResourceTree, outputDiff)
38import Gallery (buildGalleryTree) 40import Gallery (buildGalleryTree)
39 41
40 42
@@ -60,10 +62,6 @@ process inputDirPath outputDirPath =
60 putStrLn "\nINPUT DIR" 62 putStrLn "\nINPUT DIR"
61 putStrLn (show inputDir) 63 putStrLn (show inputDir)
62 64
63 outputDir <- readDirectory outputDirPath
64 putStrLn "\nOUTPUT DIR"
65 putStrLn (show outputDir)
66
67 inputTree <- readInputTree inputDir 65 inputTree <- readInputTree inputDir
68 putStrLn "\nINPUT TREE" 66 putStrLn "\nINPUT TREE"
69 putStrLn (show inputTree) 67 putStrLn (show inputTree)
@@ -79,18 +77,26 @@ process inputDirPath outputDirPath =
79 -- (or recompile everything if the config file has changed!) 77 -- (or recompile everything if the config file has changed!)
80 -- execute in parallel 78 -- execute in parallel
81 79
82 -- TODO: clean up output dir by comparing its content with the resource tree 80 cleanup resourceTree outputDirPath
83 -- aggregate both trees as list
84 -- compute the difference
85 -- sort by deepest and erase files and dirs
86 81
87 -- TODO: execute (in parallel) the resource compilation strategy list 82 -- TODO: execute (in parallel) the resource compilation strategy list
88 -- need to find a good library for that 83 -- need to find a good library for that
89 84
90 buildGalleryTree resourceTree & writeJSON (outputDirPath </> "index.json") 85 buildGalleryTree resourceTree
91 writeJSON (outputDirPath </> "viewer.json") (viewer config) 86 & writeJSON (outputDirPath </> "index.json")
87
88 viewer config
89 & writeJSON (outputDirPath </> "viewer.json")
92 90
93 where 91 where
92 cleanup :: ResourceTree -> FileName -> IO ()
93 cleanup resourceTree outputDir =
94 readDirectory outputDir
95 >>= return . outputDiff resourceTree . root
96 >>= return . sortBy (flip $ comparing length) -- nested files before dirs
97 >>= return . map (localPath . (/>) outputDir)
98 >>= mapM_ removePathForcibly
99
94 writeJSON :: ToJSON a => FileName -> a -> IO () 100 writeJSON :: ToJSON a => FileName -> a -> IO ()
95 writeJSON path obj = 101 writeJSON path obj =
96 createDirectoryIfMissing True (dropFileName path) 102 createDirectoryIfMissing True (dropFileName path)