// WatchPaths watches a set of paths, and broadcasts changes through reloader. func WatchPaths(paths, excludePatterns []string, reloader livereload.Reloader, log termlog.Logger) error { ch := make(chan []string, 1) for _, path := range paths { absPath, err := filepath.Abs(path) if err != nil { return err } if absPath[len(absPath)-1] != filepath.Separator { absPath += string(filepath.Separator) } pathchan := make(chan []string, 1) err = watch.Watch(path, batchTime, pathchan) if err != nil { return err } go func() { for files := range pathchan { files = filterFiles(absPath, files, excludePatterns, log) if len(files) > 0 { ch <- files } } }() } go reloader.Watch(ch) return nil }
// Watch watches an endpoint for changes, if it supports them. func (r Route) Watch(ch chan []string, excludePatterns []string, log termlog.Logger) error { switch r.Endpoint.(type) { case *filesystemEndpoint: ep := *r.Endpoint.(*filesystemEndpoint) pathchan := make(chan []string, 1) err := watch.Watch(string(ep), batchTime, pathchan) if err != nil { return err } go func() { for files := range pathchan { for i, fpath := range files { files[i] = path.Join( r.Path, strings.TrimPrefix(fpath, string(ep)), ) } files = filterFiles("/", files, excludePatterns, log) ch <- files } }() } return nil }