on 9ff0465 help sign in
elk/builder/src/File/Watcher.hs
76 lines 1.4 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2module File.Watcher where
4import Control.Concurrent (forkIO, threadDelay)
5import Control.Concurrent.Chan (newChan, readChan, writeChan)
6import qualified System.FSNotify as Notify
8import qualified Elm.Project as Project
9import Elm.Project (Project)
13-- GRAPH
16data Graph =
17 Graph
18 { _elm :: Map.Map Module.Raw Node
19 , _js :: Map.Map Module.Raw FilePath
20 }
23data Node =
24 Node
25 { _path :: FilePath
26 , _time :: UTCTime
27 , _needs :: Set.Set Module.Raw
28 , _blocks :: Set.Set Module.Raw
29 , _iface :: Maybe (UTCTime, Interface)
30 }
34-- ABC
37action :: Notify.Event -> IO ()
38action event =
39 case event of
40 Notify.Added path time ->
41 return ()
43 Notify.Modified path time ->
44 return ()
46 Notify.Removed path time ->
47 return ()
50watcher :: Project -> IO ()
51watcher project =
52 let
53 srcDir =
54 Project.toSourceDir project
56 action event =
57 case event of
58 Notify.Added _ _ ->
59 return ()
61 Notify.Modified path time ->
63 Notify.Removed path time ->
65 in
66 do killer <- newChan
67 mapM_ (watcherHelp killer action) [srcDir]
71watcherHelp :: Notify.Action -> FilePath -> IO ()
72watcherHelp killer action dir =
73 void $ forkIO $ Notify.withManager $ \manager ->
74 do stop <- Notify.watchTree manager dir (const True) action
75 _ <- readChan killer
76 stop