@@ -7,14 +7,19 @@ import Data.List.NonEmpty qualified as NE
77import Data.Text.Display
88import Data.Text.IO qualified as Text
99import Data.Vector (Vector )
10+ import Data.Vector qualified as Vector
1011import Effectful
12+ import Effectful.Concurrent
13+ import Effectful.Console.ByteString
1114import Effectful.Error.Static
1215import Effectful.FileSystem (FileSystem )
1316import Effectful.FileSystem qualified as FileSystem
17+ import GHC.Float
1418import System.OsPath (OsPath )
1519import System.OsPath qualified as OsPath
1620
1721import Confer.CLI.Errors
22+ import Confer.CLI.UI
1823import Confer.Config.Types
1924import Confer.Effect.Symlink (Symlink , SymlinkError (.. ))
2025import Confer.Effect.Symlink qualified as Symlink
@@ -31,32 +36,34 @@ deploy
3136 :: ( FileSystem :> es
3237 , Symlink :> es
3338 , IOE :> es
39+ , Console :> es
40+ , Concurrent :> es
3441 , Error (NonEmpty CLIError ) :> es
3542 )
3643 => Bool
3744 -> Vector Deployment
3845 -> Eff es ()
3946deploy quiet deployments = do
40- forM_ deployments $ \ d ->
41- forM_ d . facts $ \ fact -> do
42- linkFilepath <- liftIO $ OsPath. decodeFS fact . destination
43- destinationPathExists <- FileSystem. doesPathExist linkFilepath
44- if destinationPathExists
45- then do
46- result <- Symlink. testSymlink fact . destination fact . source
47- case result of
48- Left symlinkError -> do
49- let cliError = case symlinkError of
50- DoesNotExist path -> symlinkDoesNotExistError path
51- IsNotSymlink path -> pathIsNotSymlinkError path
52- AlreadyExists path -> symlinkAlreadyExistsError path
53- WrongTarget link expected actual -> wrongTargetError link expected actual
54- throwError ( NE. singleton cliError)
55- Right _ ->
56- liftIO $ Text. putStrLn $ display (linkFilepath <> " ✅ " )
57- else do
58- Symlink. createSymlink fact . source fact . destination
59- unless quiet $ do
60- liftIO $
61- Text. putStrLn $
62- " [🔗] " <> display fact
47+ let facts = deployments >>= ( . facts)
48+ Vector. iforM facts $ \ index fact -> do
49+ threadDelay 30_000
50+ let percentage = int2Double index / int2Double ( Vector. length facts)
51+ unless quiet $ printProgress " Deploying " percentage
52+ linkFilepath <- liftIO $ OsPath. decodeFS fact . destination
53+ destinationPathExists <- FileSystem. doesPathExist linkFilepath
54+ if destinationPathExists
55+ then do
56+ result <- Symlink. testSymlink fact . destination fact . source
57+ case result of
58+ Left symlinkError -> do
59+ let cliError = case symlinkError of
60+ DoesNotExist path -> symlinkDoesNotExistError path
61+ AlreadyExists path -> symlinkAlreadyExistsError path
62+ IsNotSymlink path -> pathIsNotSymlinkError path
63+ WrongTarget link expected actual -> wrongTargetError link expected actual
64+ throwError ( NE. singleton cliError)
65+ Right _ -> pure ()
66+ else do
67+ Symlink. createSymlink fact . source fact . destination
68+
69+ unless quiet $ printProgress " Deploying " 1.0
0 commit comments