WatchPaths watches a set of paths, and broadcasts changes through reloader.
(paths, excludePatterns []string, reloader livereload.Reloader, log termlog.Logger)
| 49 | |
| 50 | // WatchPaths watches a set of paths, and broadcasts changes through reloader. |
| 51 | func WatchPaths(paths, excludePatterns []string, reloader livereload.Reloader, log termlog.Logger) error { |
| 52 | wd, err := os.Getwd() |
| 53 | if err != nil { |
| 54 | return err |
| 55 | } |
| 56 | ch := make(chan []string, 1) |
| 57 | for _, path := range paths { |
| 58 | modchan := make(chan *moddwatch.Mod, 1) |
| 59 | _, err := moddwatch.Watch( |
| 60 | wd, |
| 61 | []string{path}, |
| 62 | excludePatterns, |
| 63 | batchTime, |
| 64 | modchan, |
| 65 | ) |
| 66 | if err != nil { |
| 67 | return err |
| 68 | } |
| 69 | go func() { |
| 70 | for mod := range modchan { |
| 71 | if !mod.Empty() { |
| 72 | ch <- mod.All() |
| 73 | } |
| 74 | } |
| 75 | }() |
| 76 | } |
| 77 | go reloader.Watch(ch) |
| 78 | return nil |
| 79 | } |
| 80 | |
| 81 | // WatchRoutes watches the route collection, and broadcasts changes through reloader. |
| 82 | func WatchRoutes(routes RouteCollection, reloader livereload.Reloader, excludePatterns []string, log termlog.Logger) error { |