Fixed multiple events on change
This commit is contained in:
parent
2358f76e65
commit
d2a73eec94
|
@ -8,6 +8,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InArray(str string, list []string) bool{
|
func InArray(str string, list []string) bool{
|
||||||
|
@ -52,29 +53,39 @@ func (h *Config) Watch() error{
|
||||||
}
|
}
|
||||||
|
|
||||||
watch := func(val Project){
|
watch := func(val Project){
|
||||||
|
|
||||||
watcher, _ = fsnotify.NewWatcher()
|
watcher, _ = fsnotify.NewWatcher()
|
||||||
|
|
||||||
|
// run, bin, build
|
||||||
|
val.reload = time.Now().Truncate(time.Second)
|
||||||
|
|
||||||
for _, dir := range val.Watcher.Paths {
|
for _, dir := range val.Watcher.Paths {
|
||||||
path, _ := os.Getwd()
|
path, _ := os.Getwd()
|
||||||
current = val.Watcher
|
current = val.Watcher
|
||||||
|
// add dir of project
|
||||||
if err := filepath.Walk(path + dir, walk); err != nil {
|
if err := filepath.Walk(path + dir, walk); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case event := <-watcher.Events:
|
case event := <-watcher.Events:
|
||||||
|
if time.Now().Truncate(time.Second).After(val.reload) {
|
||||||
if event.Op & fsnotify.Chmod == fsnotify.Chmod {
|
if event.Op & fsnotify.Chmod == fsnotify.Chmod {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if _, err := os.Stat(event.Name); err == nil {
|
||||||
log.Println("event:", event)
|
log.Println("event:", event)
|
||||||
|
// run, bin, build
|
||||||
|
val.reload = time.Now().Truncate(time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
case err := <-watcher.Errors:
|
case err := <-watcher.Errors:
|
||||||
log.Println("error:", err)
|
log.Println("error:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Done()
|
|
||||||
watcher.Close()
|
watcher.Close()
|
||||||
|
wg.Done()
|
||||||
}
|
}
|
||||||
|
|
||||||
// add to watcher
|
// add to watcher
|
||||||
|
|
Loading…
Reference in New Issue