-
Notifications
You must be signed in to change notification settings - Fork 0
/
resetnpm.hs
43 lines (34 loc) · 1.2 KB
/
resetnpm.hs
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
import Prelude hiding (catch)
import System.Directory
import Control.Exception
import Control.Concurrent
import System.IO
import System.IO.Unsafe
import System.IO.Error hiding (catch)
import System.FilePath.Posix
import System.Process
removeFileIfExists :: FilePath -> IO ()
removeFileIfExists fileName = removeFile fileName `catch` handleExists
where handleExists e
| isDoesNotExistError e = return ()
| otherwise = throwIO e
removeFolderIfExists :: FilePath -> IO ()
removeFolderIfExists folderName = removeDirectoryRecursive folderName `catch` handleExists
where handleExists e
| isDoesNotExistError e = return ()
| otherwise = throwIO e
currentPath :: FilePath
currentPath = unsafePerformIO $ getCurrentDirectory
nodeModulesPath = currentPath </> "node_modules"
packageLockPath = currentPath </> "package-lock.json"
removeNodeModules = removeFolderIfExists nodeModulesPath
removePackageLockJson = removeFileIfExists packageLockPath
executeNpmI = system "npm i"
main = do
putStr "Removing node_modules and package-lock.json...\n"
removeNodeModules
removePackageLockJson
putStr "Removed them.\n"
putStr "Reinstalling packages...\n"
executeNpmI
putStr "Done.\n"