From 641ea85d4da795cb2c67d9777cb3db3dfede1d8b Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 31 Dec 2019 06:58:53 +0100 Subject: compiler: add option to include static web app in the output GitHub: closes #6 --- compiler/src/Files.hs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'compiler/src/Files.hs') diff --git a/compiler/src/Files.hs b/compiler/src/Files.hs index a6649c8..a658ded 100644 --- a/compiler/src/Files.hs +++ b/compiler/src/Files.hs @@ -19,6 +19,7 @@ {-# LANGUAGE DuplicateRecordFields , DeriveGeneric + , NamedFieldPuns #-} module Files @@ -27,7 +28,8 @@ module Files , fileName, maybeFileName, subPaths, pathLength , localPath, webPath , FSNode(..), AnchoredFSNode(..) - , nodePath, nodeName, isHidden, flattenDir, filterDir, readDirectory + , nodePath, nodeName, isHidden, flattenDir, filterDir + , readDirectory, copyTo , ensureParentDir, remove, isOutdated ) where @@ -46,7 +48,8 @@ import System.Directory , getModificationTime , listDirectory , createDirectoryIfMissing - , removePathForcibly ) + , removePathForcibly + , copyFile ) import qualified System.FilePath import qualified System.FilePath.Posix @@ -146,6 +149,16 @@ readDirectory root = mkNode (Path []) >>= return . AnchoredFSNode root >>= mapM (mkNode . ((>= return . Dir path +copyTo :: FilePath -> AnchoredFSNode -> IO () +copyTo target AnchoredFSNode{anchor, root} = copyNode root + where + copyNode :: FSNode -> IO () + copyNode (File path) = + copyFile (localPath $ anchor /> path) (localPath $ target /> path) + + copyNode (Dir path items) = + createDirectoryIfMissing True (localPath $ target /> path) + >> mapM_ copyNode items ensureParentDir :: (FileName -> a -> IO b) -> FileName -> a -> IO b ensureParentDir writer filePath a = -- cgit v1.2.3