diff --git a/realize/run.go b/realize/run.go deleted file mode 100644 index 4b7b005..0000000 --- a/realize/run.go +++ /dev/null @@ -1 +0,0 @@ -package realize diff --git a/realize/watcher.go b/realize/watcher.go new file mode 100644 index 0000000..ae095fa --- /dev/null +++ b/realize/watcher.go @@ -0,0 +1,40 @@ +package realize + +import ( + "github.com/fsnotify/fsnotify" + "path/filepath" + "os" +) + +func (h *Config) Watch() error{ + + watcher, err := fsnotify.NewWatcher() + if err != nil{ + panic(err) + } + + walking := func(path string, info os.FileInfo, err error) error{ + if info.IsDir() { + if err = watcher.Add(path); err != nil { + return filepath.SkipDir + } + } + return nil + } + + // check file + if err := h.Read(); err == nil { + // loop projects + for _, val := range h.Projects { + // add paths to watcher + for _, path := range val.Watcher.Paths { + if err := filepath.Walk(path, walking); err != nil{ + panic(err) + } + } + } + return nil + }else{ + return err + } +} \ No newline at end of file