diff options
Diffstat (limited to 'compiler/src/Lib.hs')
-rw-r--r-- | compiler/src/Lib.hs | 35 |
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 | ||
27 | import GHC.Generics (Generic) | ||
28 | import Data.Function ((&)) | 27 | import Data.Function ((&)) |
29 | import Data.Ord (comparing) | 28 | import Data.Ord (comparing) |
30 | import Data.List (sortBy, length) | 29 | import Data.List (sortBy, length) |
31 | import System.Directory (createDirectoryIfMissing, removePathForcibly) | 30 | import System.Directory (createDirectoryIfMissing, removePathForcibly) |
32 | import System.FilePath (dropFileName, (</>)) | 31 | import System.FilePath (dropFileName, (</>)) |
33 | 32 | ||
34 | import Data.Aeson (ToJSON, FromJSON) | 33 | import Data.Aeson (ToJSON) |
35 | import qualified Data.Aeson as JSON | 34 | import qualified Data.Aeson as JSON |
36 | 35 | ||
36 | import Config | ||
37 | import Files (FileName, readDirectory, localPath, flattenDir, root, (/>)) | 37 | import Files (FileName, readDirectory, localPath, flattenDir, root, (/>)) |
38 | import Input (decodeYamlFile, readInputTree) | 38 | import Input (decodeYamlFile, readInputTree) |
39 | import Resource (ResourceTree, buildResourceTree, outputDiff) | 39 | import Resource (ResourceTree, buildResourceTree, outputDiff) |
40 | import Gallery (buildGalleryTree) | 40 | import Gallery (buildGalleryTree) |
41 | 41 | ||
42 | 42 | ||
43 | data CompilerConfig = CompilerConfig | ||
44 | { dummy :: Maybe String -- TODO | ||
45 | } deriving (Generic, FromJSON, Show) | ||
46 | |||
47 | data GalleryConfig = GalleryConfig | ||
48 | { compiler :: CompilerConfig | ||
49 | , viewer :: JSON.Object | ||
50 | } deriving (Generic, FromJSON, Show) | ||
51 | |||
52 | readConfig :: FileName -> IO GalleryConfig | ||
53 | readConfig = decodeYamlFile | ||
54 | |||
55 | |||
56 | process :: FilePath -> FilePath -> IO () | 43 | process :: FilePath -> FilePath -> IO () |
57 | process inputDirPath outputDirPath = | 44 | process 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 = |