-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathReset.hs
More file actions
92 lines (70 loc) · 2.54 KB
/
Reset.hs
File metadata and controls
92 lines (70 loc) · 2.54 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
{-# LANGUAGE OverloadedStrings #-}
module Lamdera.CLI.Reset where
import qualified Data.Text as T
import qualified Data.List as List
import System.FilePath ((</>))
import qualified System.Directory as Dir
import qualified Stuff as PerUserCache
import qualified Reporting
import qualified Reporting.Doc as D
import Lamdera
import Lamdera.Progress
import qualified Lamdera.CLI.Login
import qualified Lamdera.Version
run :: () -> () -> IO ()
run () () = do
debug_ "Starting reset..."
elmHome <- PerUserCache.getElmHome
legacyElmHome <- Dir.getAppUserDataDirectory "lamdera"
root <- getProjectRootMaybe
let
elmStuff = (root & withDefault "./") </> "elm-stuff"
lamderaLegacy = (root & withDefault "./") </> "lamdera-stuff"
lamderaCliLogin = elmHome </> Lamdera.CLI.Login.tokenFile
progress "Here is the plan:\n"
if List.isInfixOf [ostype] [MacOS, Linux]
then
report $ D.fillSep ["-", D.yellow "Remove artifacts in", D.fromChars elmHome]
else
planNukeDir elmHome ""
planNukeFile lamderaCliLogin ""
planNukeDir elmStuff ""
planNukeDir legacyElmHome "(Legacy)"
planNukeDir lamderaLegacy "(Legacy)"
progress ""
onlyWhen_ (not <$> doesDirectoryExist elmStuff) $ do
report $ D.fillSep [D.red "Warning:", "you're","not","in","an","Elm","project","folder,", "so","I","can","only","reset","the","global","Elm","cache."]
progress ""
approveReset <- Reporting.ask $
D.fillSep [ "Shall I proceed?", D.red "(this cannot be undone)", "[Y/n]: " ]
if approveReset
then do
if List.isInfixOf [ostype] [MacOS, Linux]
then do
progress $ "Removing artifacts in " <> elmHome
let packageDir = elmHome </> Lamdera.Version.elm </> "packages"
onlyWhen_ (doesDirectoryExist packageDir) $ do
callCommand $ "find " <> packageDir <> " | grep 'artifacts.*\\.dat' | xargs rm -r"
else do
nukeDir elmHome
nukeFile lamderaCliLogin
nukeDir elmStuff
nukeDir legacyElmHome
nukeDir lamderaLegacy
else
progress "\nOkay, I did not reset anything."
pure ()
planNukeDir dir suffix =
onlyWhen_ (doesDirectoryExist dir) $ do
report $ D.fillSep ["-", D.red "Remove", D.fromChars dir, suffix]
planNukeFile file suffix =
onlyWhen_ (doesFileExist file) $ do
report $ D.fillSep ["-", D.red "Remove", D.fromChars file, suffix]
nukeDir dir =
onlyWhen_ (doesDirectoryExist dir) $ do
progress $ "Removing " <> dir
rmdir dir
nukeFile file =
onlyWhen_ (doesFileExist file) $ do
progress $ "Removing " <> file
remove file