1
1
mirror of https://github.com/srid/ema.git synced 2024-11-29 09:25:14 +03:00

Be lenient on missing staticAssets

This commit is contained in:
Sridhar Ratnakumar 2021-05-10 18:19:42 -04:00
parent e7bf0333da
commit e3a05de882
2 changed files with 9 additions and 4 deletions

View File

@ -7,6 +7,7 @@
- Unicode normalize slugs using NFC - Unicode normalize slugs using NFC
- Add `decodeSlug` and `encodeSlug` - Add `decodeSlug` and `encodeSlug`
- Add default implementation based on Enum for `staticRoute` - Add default implementation based on Enum for `staticRoute`
- Warn, without failing, on missing `staticAssets` during static generation
- Helpers - Helpers
- Helpers.FileSystem - Helpers.FileSystem
- add `mountOnLVar` - add `mountOnLVar`

View File

@ -6,9 +6,9 @@ module Ema.Generate where
import Control.Exception (throw) import Control.Exception (throw)
import Control.Monad.Logger import Control.Monad.Logger
import Ema.Class import Ema.Class (Ema (staticAssets, staticRoutes), MonadEma)
import Ema.Route (routeFile) import Ema.Route (routeFile)
import System.Directory (copyFile, createDirectoryIfMissing, doesDirectoryExist, doesFileExist) import System.Directory (copyFile, createDirectoryIfMissing, doesDirectoryExist, doesFileExist, doesPathExist)
import System.FilePath (takeDirectory, (</>)) import System.FilePath (takeDirectory, (</>))
import System.FilePattern.Directory (getDirectoryFiles) import System.FilePattern.Directory (getDirectoryFiles)
@ -24,7 +24,7 @@ generate ::
m () m ()
generate dest model render = do generate dest model render = do
unlessM (liftIO $ doesDirectoryExist dest) $ do unlessM (liftIO $ doesDirectoryExist dest) $ do
error "Destination does not exist" error $ "Destination does not exist: " <> toText dest
let routes = staticRoutes model let routes = staticRoutes model
log LevelInfo $ "Writing " <> show (length routes) <> " routes" log LevelInfo $ "Writing " <> show (length routes) <> " routes"
forM_ routes $ \r -> do forM_ routes $ \r -> do
@ -35,7 +35,11 @@ generate dest model render = do
createDirectoryIfMissing True (takeDirectory fp) createDirectoryIfMissing True (takeDirectory fp)
writeFileLBS fp s writeFileLBS fp s
forM_ (staticAssets $ Proxy @route) $ \staticPath -> do forM_ (staticAssets $ Proxy @route) $ \staticPath -> do
copyDirRecursively staticPath dest liftIO (doesPathExist staticPath) >>= \case
True ->
copyDirRecursively staticPath dest
False ->
log LevelWarn $ toText $ "? " <> staticPath <> " (missing)"
newtype StaticAssetMissing = StaticAssetMissing FilePath newtype StaticAssetMissing = StaticAssetMissing FilePath
deriving (Show, Exception) deriving (Show, Exception)