aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/Lib.hs
diff options
context:
space:
mode:
authorpacien2019-12-26 08:03:31 +0100
committerpacien2019-12-26 08:03:31 +0100
commitaead07929e6ed13375b86539b1679a88993c9cf5 (patch)
treea3709043d1d27abb93479c9a0e199870acce3c55 /compiler/src/Lib.hs
parent3cd1ed2ed39a31ed2c63e9e116edccd3d7946435 (diff)
downloadldgallery-aead07929e6ed13375b86539b1679a88993c9cf5.tar.gz
compiler: extract config and remove utils
Diffstat (limited to 'compiler/src/Lib.hs')
-rw-r--r--compiler/src/Lib.hs35
1 files changed, 11 insertions, 24 deletions
diff --git a/compiler/src/Lib.hs b/compiler/src/Lib.hs
index 643e5f6..b2bbe15 100644
--- a/compiler/src/Lib.hs
+++ b/compiler/src/Lib.hs
@@ -24,47 +24,28 @@ module Lib
24 ) where 24 ) where
25 25
26 26
27import GHC.Generics (Generic)
28import Data.Function ((&)) 27import Data.Function ((&))
29import Data.Ord (comparing) 28import Data.Ord (comparing)
30import Data.List (sortBy, length) 29import Data.List (sortBy, length)
31import System.Directory (createDirectoryIfMissing, removePathForcibly) 30import System.Directory (createDirectoryIfMissing, removePathForcibly)
32import System.FilePath (dropFileName, (</>)) 31import System.FilePath (dropFileName, (</>))
33 32
34import Data.Aeson (ToJSON, FromJSON) 33import Data.Aeson (ToJSON)
35import qualified Data.Aeson as JSON 34import qualified Data.Aeson as JSON
36 35
36import Config
37import Files (FileName, readDirectory, localPath, flattenDir, root, (/>)) 37import Files (FileName, readDirectory, localPath, flattenDir, root, (/>))
38import Input (decodeYamlFile, readInputTree) 38import Input (decodeYamlFile, readInputTree)
39import Resource (ResourceTree, buildResourceTree, outputDiff) 39import Resource (ResourceTree, buildResourceTree, outputDiff)
40import Gallery (buildGalleryTree) 40import Gallery (buildGalleryTree)
41 41
42 42
43data CompilerConfig = CompilerConfig
44 { dummy :: Maybe String -- TODO
45 } deriving (Generic, FromJSON, Show)
46
47data GalleryConfig = GalleryConfig
48 { compiler :: CompilerConfig
49 , viewer :: JSON.Object
50 } deriving (Generic, FromJSON, Show)
51
52readConfig :: FileName -> IO GalleryConfig
53readConfig = decodeYamlFile
54
55
56process :: FilePath -> FilePath -> IO () 43process :: FilePath -> FilePath -> IO ()
57process inputDirPath outputDirPath = 44process inputDirPath outputDirPath =
58 do 45 do
59 config <- readConfig (inputDirPath </> "gallery.yaml") 46 config <- readConfig (inputDirPath </> "gallery.yaml")
60
61 inputDir <- readDirectory inputDirPath 47 inputDir <- readDirectory inputDirPath
62 putStrLn "\nINPUT DIR"
63 putStrLn (show inputDir)
64
65 inputTree <- readInputTree inputDir 48 inputTree <- readInputTree inputDir
66 putStrLn "\nINPUT TREE"
67 putStrLn (show inputTree)
68 49
69 let resourceTree = buildResourceTree inputTree 50 let resourceTree = buildResourceTree inputTree
70 putStrLn "\nRESOURCE TREE" 51 putStrLn "\nRESOURCE TREE"
@@ -77,11 +58,11 @@ process inputDirPath outputDirPath =
77 -- (or recompile everything if the config file has changed!) 58 -- (or recompile everything if the config file has changed!)
78 -- execute in parallel 59 -- execute in parallel
79 60
80 cleanup resourceTree outputDirPath
81
82 -- TODO: execute (in parallel) the resource compilation strategy list 61 -- TODO: execute (in parallel) the resource compilation strategy list
83 -- need to find a good library for that 62 -- need to find a good library for that
84 63
64 cleanup resourceTree outputDirPath
65
85 buildGalleryTree resourceTree 66 buildGalleryTree resourceTree
86 & writeJSON (outputDirPath </> "index.json") 67 & writeJSON (outputDirPath </> "index.json")
87 68
@@ -95,7 +76,13 @@ process inputDirPath outputDirPath =
95 >>= return . outputDiff resourceTree . root 76 >>= return . outputDiff resourceTree . root
96 >>= return . sortBy (flip $ comparing length) -- nested files before dirs 77 >>= return . sortBy (flip $ comparing length) -- nested files before dirs
97 >>= return . map (localPath . (/>) outputDir) 78 >>= return . map (localPath . (/>) outputDir)
98 >>= mapM_ removePathForcibly 79 >>= mapM_ remove
80
81 remove :: FileName -> IO ()
82 remove path =
83 do
84 putStrLn $ "Removing: " ++ path
85 removePathForcibly path
99 86
100 writeJSON :: ToJSON a => FileName -> a -> IO () 87 writeJSON :: ToJSON a => FileName -> a -> IO ()
101 writeJSON path obj = 88 writeJSON path obj =