on master help sign in
executable-config: Better handling of missing config directories
commita84bf894db9e096185f96e676e3ae2047e0c3915 authorAli Abrar <aliabrar@gmail.com> dateThu 9 Aug 2018, 22:43 (8 years ago) parentb6b6b5e
1 file changed+15−12
lib/executable-config/inject/src/Obelisk/ExecutableConfig/Inject.hs+15−12
lib/executable-config/inject/src/Obelisk/ExecutableConfig/Inject.hs+15−12
@@ -1,7 +1,7 @@
11{-# LANGUAGE OverloadedStrings #-}
22module Obelisk.ExecutableConfig.Inject where
33
4−import Control.Monad (forM, mapM_)
4+import Control.Monad (mapM_)
55import Control.Monad.IO.Class (MonadIO, liftIO)
66import Data.Semigroup ((<>))
77import Data.ByteString (ByteString)
@@ -34,15 +34,18 @@ injectExecutableConfigs = do
3434 cfgC <- getConfigs "config/common"
3535 cfgF <- getConfigs "config/frontend"
3636 mapM_ (uncurry injectPure) (cfgC <> cfgF)
37− where
38− getConfigs :: MonadIO m => FilePath -> m [(Text, Text)]
39− getConfigs fp = liftIO $ do
37+
38+getConfigs :: MonadIO m => FilePath -> m [(Text, Text)]
39+getConfigs fp = liftIO $ do
40+ dir <- doesDirectoryExist fp
41+ if dir
42+ then do
4043 ps <- listDirectory fp
41− fmap concat $ forM ps $ \p -> do
42− let fullpath = fp </> p
43− dir <- doesDirectoryExist p
44− if dir
45− then getConfigs fullpath
46− else do
47− v <- T.readFile fullpath
48− return [(T.pack fullpath, v)]
44+ fmap concat $ mapM (\p -> getConfigs $ fp </> p) ps
45+ else do
46+ file <- doesFileExist fp
47+ if file
48+ then do
49+ f <- T.readFile fp
50+ return [(T.pack fp, f)]
51+ else return []