diff --git a/waspc/src/Generator/FileDraft/CopyFileDraft.hs b/waspc/src/Generator/FileDraft/CopyFileDraft.hs index a108a0db73..86ab4f79ec 100644 --- a/waspc/src/Generator/FileDraft/CopyFileDraft.hs +++ b/waspc/src/Generator/FileDraft/CopyFileDraft.hs @@ -2,6 +2,8 @@ module Generator.FileDraft.CopyFileDraft ( CopyFileDraft(..) ) where +import Control.Monad (when) + import StrongPath (Path, Abs, Rel, File, ()) import qualified StrongPath as SP import Generator.Common (ProjectRootDir) @@ -19,6 +21,12 @@ data CopyFileDraft = CopyFileDraft instance Writeable CopyFileDraft where write absDstDirPath draft = do createDirectoryIfMissing True (SP.toFilePath $ SP.parent absDraftDstPath) - copyFile (SP.toFilePath $ _srcPath draft) (SP.toFilePath $ absDraftDstPath) + + -- NOTE(matija): + fileExists <- doesFileExist (SP.toFilePath $ _srcPath draft) + when fileExists + (copyFile (SP.toFilePath $ _srcPath draft) (SP.toFilePath $ absDraftDstPath)) + + --copyFile (SP.toFilePath $ _srcPath draft) (SP.toFilePath $ absDraftDstPath) where absDraftDstPath = absDstDirPath (_dstPath draft) diff --git a/waspc/src/Generator/FileDraft/WriteableMonad.hs b/waspc/src/Generator/FileDraft/WriteableMonad.hs index cfea15f33e..ae143a8547 100644 --- a/waspc/src/Generator/FileDraft/WriteableMonad.hs +++ b/waspc/src/Generator/FileDraft/WriteableMonad.hs @@ -46,6 +46,10 @@ class (Monad m) => WriteableMonad m where -> Aeson.Value -- ^ JSON to be provided as template data. -> m Text + doesFileExist + :: FilePath + -> m Bool + instance WriteableMonad IO where createDirectoryIfMissing = System.Directory.createDirectoryIfMissing copyFile = System.Directory.copyFile @@ -53,3 +57,4 @@ instance WriteableMonad IO where getTemplateFileAbsPath = Templates.getTemplateFileAbsPath getTemplatesDirAbsPath = Templates.getTemplatesDirAbsPath compileAndRenderTemplate = Templates.compileAndRenderTemplate + doesFileExist = System.Directory.doesFileExist diff --git a/waspc/test/Generator/MockWriteableMonad.hs b/waspc/test/Generator/MockWriteableMonad.hs index 75ccad71c4..be7da440b2 100644 --- a/waspc/test/Generator/MockWriteableMonad.hs +++ b/waspc/test/Generator/MockWriteableMonad.hs @@ -61,6 +61,9 @@ instance WriteableMonad MockWriteableMonad where (_, config) <- get return $ (compileAndRenderTemplate_impl config) path json + doesFileExist path = MockWriteableMonad (return True) + + modifyLogs :: MonadState (a, b) m => (a -> a) -> m () modifyLogs f = modify (\(logs, config) -> (f logs, config))