aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/src/Files.hs5
-rw-r--r--compiler/src/Input.hs18
2 files changed, 18 insertions, 5 deletions
diff --git a/compiler/src/Files.hs b/compiler/src/Files.hs
index 079da61..d1363a1 100644
--- a/compiler/src/Files.hs
+++ b/compiler/src/Files.hs
@@ -23,7 +23,7 @@
23 23
24module Files 24module Files
25 ( FileName, LocalPath, WebPath, Path 25 ( FileName, LocalPath, WebPath, Path
26 , (</>), (</), (/>), localPath, webPath 26 , (</>), (</), (/>), (<.>), localPath, webPath
27 , FSNode(..), AnchoredFSNode(..) 27 , FSNode(..), AnchoredFSNode(..)
28 , nodePath, nodeName, isHidden, flattenDir, filterDir, readDirectory 28 , nodePath, nodeName, isHidden, flattenDir, filterDir, readDirectory
29 , ensureParentDir, remove, isOutdated 29 , ensureParentDir, remove, isOutdated
@@ -62,6 +62,9 @@ path </ file = file:path
62(/>) :: FileName -> Path -> Path 62(/>) :: FileName -> Path -> Path
63file /> path = path ++ [file] 63file /> path = path ++ [file]
64 64
65(<.>) :: Path -> String -> Path
66(filename:pathto) <.> ext = System.FilePath.addExtension filename ext : pathto
67
65localPath :: Path -> LocalPath 68localPath :: Path -> LocalPath
66localPath = System.FilePath.joinPath . reverse 69localPath = System.FilePath.joinPath . reverse
67 70
diff --git a/compiler/src/Input.hs b/compiler/src/Input.hs
index c90db5c..597394e 100644
--- a/compiler/src/Input.hs
+++ b/compiler/src/Input.hs
@@ -34,10 +34,12 @@ import Control.Exception (Exception, throwIO)
34import Control.Monad.IO.Class (MonadIO, liftIO) 34import Control.Monad.IO.Class (MonadIO, liftIO)
35import Data.Function ((&)) 35import Data.Function ((&))
36import Data.Maybe (mapMaybe, catMaybes) 36import Data.Maybe (mapMaybe, catMaybes)
37import Data.Bool (bool)
37import Data.List (find) 38import Data.List (find)
38import Data.Yaml (ParseException, decodeFileEither) 39import Data.Yaml (ParseException, decodeFileEither)
39import Data.Aeson (FromJSON) 40import Data.Aeson (FromJSON)
40import System.FilePath (isExtensionOf, dropExtension) 41import System.FilePath (isExtensionOf, dropExtension)
42import System.Directory (doesFileExist)
41 43
42import Files 44import Files
43 45
@@ -76,15 +78,23 @@ emptySidecar = Sidecar
76 , description = Nothing 78 , description = Nothing
77 , tags = Nothing } 79 , tags = Nothing }
78 80
81sidecarExt :: String
82sidecarExt = "yaml"
83
84readSidecarFile :: FilePath -> IO Sidecar
85readSidecarFile filepath =
86 doesFileExist filepath
87 >>= bool (return Nothing) (decodeYamlFile filepath)
88 >>= return . maybe emptySidecar id
89
79 90
80readInputTree :: AnchoredFSNode -> IO InputTree 91readInputTree :: AnchoredFSNode -> IO InputTree
81readInputTree (AnchoredFSNode anchor root@Dir{}) = mkDirNode root 92readInputTree (AnchoredFSNode anchor root@Dir{}) = mkDirNode root
82 where 93 where
83 mkInputNode :: FSNode -> IO (Maybe InputTree) 94 mkInputNode :: FSNode -> IO (Maybe InputTree)
84 mkInputNode (File path@(filename:pathto)) | ".yaml" `isExtensionOf` filename = 95 mkInputNode (File path@(filename:_)) | not (sidecarExt `isExtensionOf` filename) =
85 (decodeYamlFile (localPath $ anchor /> path) :: IO (Maybe Sidecar)) 96 readSidecarFile (localPath $ anchor /> path <.> sidecarExt)
86 >>= return . maybe emptySidecar id 97 >>= return . InputFile path
87 >>= return . InputFile ((dropExtension filename):pathto)
88 >>= return . Just 98 >>= return . Just
89 mkInputNode File{} = return Nothing 99 mkInputNode File{} = return Nothing
90 mkInputNode dir@Dir{} = mkDirNode dir >>= return . Just 100 mkInputNode dir@Dir{} = mkDirNode dir >>= return . Just