Watch watches an endpoint for changes, if it supports them.
( ch chan []string, excludePatterns []string, log termlog.Logger, )
| 13 | |
| 14 | // Watch watches an endpoint for changes, if it supports them. |
| 15 | func (r Route) Watch( |
| 16 | ch chan []string, |
| 17 | excludePatterns []string, |
| 18 | log termlog.Logger, |
| 19 | ) (*moddwatch.Watcher, error) { |
| 20 | wd, err := os.Getwd() |
| 21 | if err != nil { |
| 22 | return nil, err |
| 23 | } |
| 24 | var watcher *moddwatch.Watcher |
| 25 | switch r.Endpoint.(type) { |
| 26 | case *filesystemEndpoint: |
| 27 | ep := *r.Endpoint.(*filesystemEndpoint) |
| 28 | modchan := make(chan *moddwatch.Mod, 1) |
| 29 | watcher, err = moddwatch.Watch( |
| 30 | wd, |
| 31 | []string{ep.Root + "/...", "**"}, |
| 32 | excludePatterns, |
| 33 | batchTime, |
| 34 | modchan, |
| 35 | ) |
| 36 | if err != nil { |
| 37 | return nil, err |
| 38 | } |
| 39 | go func() { |
| 40 | for mod := range modchan { |
| 41 | if !mod.Empty() { |
| 42 | ch <- mod.All() |
| 43 | } |
| 44 | } |
| 45 | }() |
| 46 | } |
| 47 | return watcher, nil |
| 48 | } |
| 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 { |