From 47f4c946a43f01bd2c513c89eb8033f52825e8cd Mon Sep 17 00:00:00 2001 From: jimafisk Date: Mon, 29 May 2023 03:51:13 -0400 Subject: [PATCH] Only watch project dirs for changes. --- cmd/serve/watcher.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd/serve/watcher.go b/cmd/serve/watcher.go index 33afe788..4ea5ff5f 100644 --- a/cmd/serve/watcher.go +++ b/cmd/serve/watcher.go @@ -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) @@ -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())