-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathCommon.hs
More file actions
66 lines (60 loc) · 2.35 KB
/
Common.hs
File metadata and controls
66 lines (60 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
module Wasp.Cli.Command.Common
( readWaspCompileInfo,
throwIfExeIsNotAvailable,
deleteDirectoryIfExistsVerbosely,
)
where
import qualified Control.Monad.Except as E
import Control.Monad.IO.Class (liftIO)
import qualified Data.Text as T
import NeatInterpolation (trimming)
import StrongPath (Abs, Dir, Path')
import qualified StrongPath as SP
import StrongPath.Operations
import System.Directory (findExecutable)
import Wasp.Cli.Command (Command, CommandError (..))
import Wasp.Cli.Command.Message (cliSendMessageC)
import qualified Wasp.Generator.WaspInfo as WI
import qualified Wasp.Message as Msg
import Wasp.Project (WaspProjectDir)
import qualified Wasp.Project.Common as Project.Common
import qualified Wasp.Util.IO as IOUtil
readWaspCompileInfo :: Path' Abs (Dir WaspProjectDir) -> IO String
readWaspCompileInfo waspDir =
either showError showWaspInfo
<$> WI.safeRead generatedAppDir
where
showError WI.NotFound = "No compile information found"
showError WI.IncompatibleFormat = "Incompatible compile information"
showWaspInfo waspInfo =
T.unpack
[trimming|
${buildType} build, generated at ${generatedAt}, by Wasp ${waspVersion}.
|]
where
buildType = T.pack $ show $ WI.buildType waspInfo
generatedAt = T.pack $ show $ WI.generatedAt waspInfo
waspVersion = T.pack $ WI.waspVersion waspInfo
generatedAppDir =
waspDir
</> Project.Common.dotWaspDirInWaspProjectDir
</> Project.Common.generatedAppDirInDotWaspDir
throwIfExeIsNotAvailable :: String -> String -> Command ()
throwIfExeIsNotAvailable exeName explanationMsg = do
liftIO (findExecutable exeName) >>= \case
Just _ -> return ()
Nothing ->
E.throwError $
CommandError ("Couldn't find `" <> exeName <> "` executable") explanationMsg
deleteDirectoryIfExistsVerbosely :: Path' Abs (Dir d) -> Command ()
deleteDirectoryIfExistsVerbosely dir = do
cliSendMessageC $ Msg.Start $ "Deleting the " ++ dirName ++ " directory..."
dirExist <- liftIO $ IOUtil.doesDirectoryExist dir
if dirExist
then do
liftIO $ IOUtil.removeDirectory dir
cliSendMessageC $ Msg.Success $ "Deleted the " ++ dirName ++ " directory."
else do
cliSendMessageC $ Msg.Success $ "Nothing to delete: The " ++ dirName ++ " directory does not exist."
where
dirName = SP.toFilePath $ basename dir