module Development.Shake.Plus.File (
copyFile'
, copyFileChanged
, readFile'
, readFileLines
, readFileIn'
, readFileWithin
, writeFile'
, writeFileLines
, writeFileIn'
, writeFileWithin
, writeFileChanged
, writeFileChangedIn
, writeFileChangedWithin
, removeFiles
, removeFilesAfter
) where
import Control.Comonad.Env as E
import Control.Exception.Extra
import qualified Development.Shake
import Development.Shake.Plus.Core
import Path
import RIO
import qualified RIO.Text as T
import Within
copyFile' :: (MonadAction m, Partial) => Path Rel File -> Path Rel File -> m ()
copyFile' x y = liftAction $ Development.Shake.copyFile' (toFilePath x) (toFilePath y)
copyFileChanged :: (MonadAction m, Partial) => Path Rel File -> Path Rel File -> m ()
copyFileChanged x y = liftAction $ Development.Shake.copyFileChanged (toFilePath x) (toFilePath y)
readFile' :: (MonadAction m, Partial) => Path Rel File -> m Text
readFile' = liftAction . fmap T.pack . Development.Shake.readFile' . toFilePath
readFileLines :: (MonadAction m, Partial) => Path Rel File -> m [Text]
readFileLines = liftAction . fmap (fmap T.pack) . Development.Shake.readFileLines . toFilePath
readFileIn' :: MonadAction m => Path Rel Dir -> Path Rel File -> m Text
readFileIn' x y = readFile' $ x </> y
readFileWithin :: MonadAction m => Within Rel (Path Rel File) -> m Text
readFileWithin = readFile' . liftA2 (</>) E.ask extract
writeFile' :: (MonadAction m, Partial) => Path Rel File -> Text -> m ()
writeFile' x y = liftAction $ Development.Shake.writeFile' (toFilePath x) (T.unpack y)
writeFileLines :: (MonadAction m, Partial) => Path Rel File -> [Text] -> m ()
writeFileLines x y = liftAction $ Development.Shake.writeFileLines (toFilePath x) (fmap T.unpack y)
writeFileIn' :: MonadAction m => Path Rel Dir -> Path Rel File -> Text -> m ()
writeFileIn' x y = writeFile' $ x </> y
writeFileWithin :: MonadAction m => Within Rel (Path Rel File) -> Text -> m ()
writeFileWithin = writeFile' . liftA2 (</>) E.ask extract
writeFileChanged :: (MonadAction m, Partial) => Path b File -> Text -> m ()
writeFileChanged x y = liftAction $ Development.Shake.writeFileChanged (toFilePath x) (T.unpack y)
writeFileChangedIn :: MonadAction m => Path Rel Dir -> Path Rel File -> Text -> m ()
writeFileChangedIn x y = writeFileChanged $ x </> y
writeFileChangedWithin :: MonadAction m => Within Rel (Path Rel File) -> Text -> m ()
writeFileChangedWithin = writeFileChanged . liftA2 (</>) E.ask extract
removeFiles :: MonadAction m => Path b File -> [FilePattern] -> m ()
removeFiles x y = liftAction . liftIO $ Development.Shake.removeFiles (toFilePath x) y
removeFilesAfter :: MonadAction m => Path Rel Dir -> [FilePattern] -> m ()
removeFilesAfter x y = liftAction $ Development.Shake.removeFilesAfter (toFilePath x) y