mirror of
https://github.com/beego/bee.git
synced 2024-12-25 14:50:51 +00:00
skip TMP files and gofmt events
This commit is contained in:
parent
7e4fd3f528
commit
0feb778d4d
21
watch.go
21
watch.go
@ -6,9 +6,9 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -28,14 +28,21 @@ func NewWatcher(paths []string) {
|
||||
select {
|
||||
case e := <-watcher.Event:
|
||||
isbuild := true
|
||||
if t, ok := eventTime[e.String()]; ok {
|
||||
|
||||
// Skip TMP files for Sublime Text.
|
||||
if checkTMPFile(e.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
if t, ok := eventTime[e.Name]; ok {
|
||||
// if 500ms change many times, then ignore it.
|
||||
// for liteide often gofmt code after save.
|
||||
if t.Add(time.Millisecond * 500).After(time.Now()) {
|
||||
fmt.Println("[SKIP]", e.String())
|
||||
isbuild = false
|
||||
}
|
||||
}
|
||||
eventTime[e.String()] = time.Now()
|
||||
eventTime[e.Name] = time.Now()
|
||||
|
||||
if isbuild {
|
||||
fmt.Println(e)
|
||||
@ -106,3 +113,11 @@ func Start(appname string) {
|
||||
|
||||
go cmd.Run()
|
||||
}
|
||||
|
||||
// checkTMPFile returns true if the event was for TMP files.
|
||||
func checkTMPFile(name string) bool {
|
||||
if strings.HasSuffix(strings.ToLower(name), ".tmp") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user