aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/Resource.hs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/src/Resource.hs')
-rw-r--r--compiler/src/Resource.hs35
1 files changed, 30 insertions, 5 deletions
diff --git a/compiler/src/Resource.hs b/compiler/src/Resource.hs
index 04e315a..60b783e 100644
--- a/compiler/src/Resource.hs
+++ b/compiler/src/Resource.hs
@@ -22,10 +22,13 @@
22module Resource 22module Resource
23 ( ResourceTree(..) 23 ( ResourceTree(..)
24 , buildResourceTree 24 , buildResourceTree
25 , flattenResourceTree
26 , outputDiff
25 ) where 27 ) where
26 28
27 29
28import Data.Function ((&)) 30import Data.Function ((&))
31import Data.List ((\\))
29import Files 32import Files
30import Input 33import Input
31 34
@@ -34,25 +37,47 @@ import Input
34data ResourceTree = 37data ResourceTree =
35 ItemResource 38 ItemResource
36 { sidecar :: Sidecar 39 { sidecar :: Sidecar
37 , path :: Path 40 , resPath :: Path
38 , itemThumbnailPath :: Path } 41 , itemThumbnailPath :: Path }
39 | DirResource 42 | DirResource
40 { items :: [ResourceTree] 43 { items :: [ResourceTree]
41 , path :: Path 44 , resPath :: Path
42 , dirThumbnailPath :: Maybe Path } 45 , dirThumbnailPath :: Maybe Path }
43 deriving Show 46 deriving Show
44 47
45 48
46 -- TODO: actually generate compilation strategies 49-- TODO: actually generate compilation strategies
47buildResourceTree :: InputTree -> ResourceTree 50buildResourceTree :: InputTree -> ResourceTree
48buildResourceTree = resNode 51buildResourceTree = resNode
49 where 52 where
50 resNode (InputFile path sidecar) = 53 resNode (InputFile path sidecar) =
51 ItemResource sidecar (itemsDir /> path) (thumbnailsDir /> path) 54 ItemResource
55 { sidecar = sidecar
56 , resPath = itemsDir /> path
57 , itemThumbnailPath = thumbnailsDir /> path }
52 58
53 resNode (InputDir path thumbnailPath items) = 59 resNode (InputDir path thumbnailPath items) =
54 map resNode items 60 map resNode items
55 & \dirItems -> DirResource dirItems (itemsDir /> path) Nothing 61 & \dirItems -> DirResource
62 { items = dirItems
63 , resPath = itemsDir /> path
64 , dirThumbnailPath = fmap ((/>) thumbnailsDir) thumbnailPath }
56 65
57 itemsDir = "items" 66 itemsDir = "items"
58 thumbnailsDir = "thumbnails" 67 thumbnailsDir = "thumbnails"
68
69
70flattenResourceTree :: ResourceTree -> [ResourceTree]
71flattenResourceTree item@ItemResource{} = [item]
72flattenResourceTree dir@(DirResource items _ _) =
73 dir:(concatMap flattenResourceTree items)
74
75
76outputDiff :: ResourceTree -> FSNode -> [Path]
77outputDiff resources ref = (fsPaths ref) \\ (resPaths resources)
78 where
79 resPaths :: ResourceTree -> [Path]
80 resPaths = map resPath . flattenResourceTree
81
82 fsPaths :: FSNode -> [Path]
83 fsPaths = map nodePath . tail . flattenDir