Skip to content

Commit

Permalink
Only watch project dirs for changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimafisk committed May 29, 2023
1 parent 66eaa6b commit 47f4c94
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cmd/serve/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ func (w *watcher) watch(buildPath string, Build buildFunc) {
// Die on any error or will loop infinitely
log.Fatal("Error watching for changes: %w", err)
}
if err := w.Add("plenti.json"); err != nil {
log.Fatal("couldn't add 'plenti.json' to watcher %w", err)
}
if err := w.Add("package.json"); err != nil {
log.Fatal("couldn't add 'package.json' to watcher %w", err)
}

done := make(chan bool)

Expand Down Expand Up @@ -90,13 +96,23 @@ func (w *watcher) watchDir(buildPath string) fs.WalkDirFunc {
return filepath.SkipDir
}
// Add watchers only to nested directory.
if fi.IsDir() {
watchingDirs := []string{"core", "content", "layouts", "media", "static"}
if fi.IsDir() && contains(watchingDirs, fi.Name()) {
return w.Add(path)
}
return nil
}
}

func contains(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}

func logEvent(event fsnotify.Event, w *watcher) {
if event.Op&fsnotify.Create == fsnotify.Create {
build.Log("File create detected: " + event.String())
Expand Down

0 comments on commit 47f4c94

Please sign in to comment.