Skip to content

Commit

Permalink
feat: support exts
Browse files Browse the repository at this point in the history
  • Loading branch information
whatwewant committed Jul 25, 2024
1 parent 1c9ce06 commit 54bce94
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func main(t *testing.T) {
watcher := watcher.New(&watcher.Config{
Context: path.Join(pwd, "example/program"),
Ignores: []string{},
Exts: []string{".go", ".mod", ".sum"},
Commands: []string{
"go run .",
},
Expand Down
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.18

require (
github.com/go-zoox/cli v1.3.2
github.com/go-zoox/fs v1.3.13
github.com/go-zoox/logger v1.4.5
github.com/go-zoox/fs v1.3.15
github.com/go-zoox/logger v1.5.1
github.com/go-zoox/zoox v1.11.8
)

Expand All @@ -14,19 +14,19 @@ require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/go-zoox/cache v1.0.4 // indirect
github.com/go-zoox/chalk v1.0.2 // indirect
github.com/go-zoox/compress v1.0.1 // indirect
github.com/go-zoox/concurrency v1.2.0 // indirect
github.com/go-zoox/config v1.2.10 // indirect
github.com/go-zoox/cookie v1.2.0 // indirect
github.com/go-zoox/core-utils v1.2.14 // indirect
github.com/go-zoox/core-utils v1.4.11 // indirect
github.com/go-zoox/counter v1.2.0 // indirect
github.com/go-zoox/cron v1.1.2 // indirect
github.com/go-zoox/crypto v1.1.8 // indirect
github.com/go-zoox/datetime v1.1.1 // indirect
github.com/go-zoox/datetime v1.3.1 // indirect
github.com/go-zoox/debug v1.0.1 // indirect
github.com/go-zoox/dotenv v1.2.3 // indirect
github.com/go-zoox/encoding v1.2.1 // indirect
Expand All @@ -49,7 +49,7 @@ require (
github.com/go-zoox/tag v1.2.3 // indirect
github.com/go-zoox/uuid v0.0.1 // indirect
github.com/goccy/go-yaml v1.9.8 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
Expand All @@ -61,15 +61,15 @@ require (
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sevlyar/go-daemon v0.1.6 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/tidwall/gjson v1.15.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/urfave/cli/v2 v2.24.4 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
16 changes: 16 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
Expand Down Expand Up @@ -56,6 +58,8 @@ github.com/go-zoox/core-utils v1.0.12/go.mod h1:EknM3KLL6/kagL95wZbWE7mRRcYCG/fH
github.com/go-zoox/core-utils v1.0.13/go.mod h1:EknM3KLL6/kagL95wZbWE7mRRcYCG/fHqiJ/EH0ihAs=
github.com/go-zoox/core-utils v1.2.14 h1:Z6x9QTgfBfhbSOOPEDLqLs9UGBWkXgBpVPlJ4pI68yk=
github.com/go-zoox/core-utils v1.2.14/go.mod h1:raOOwr2l2sJQyjR0Dg33sg0ry4U1/L2eNTuLFRpUXWs=
github.com/go-zoox/core-utils v1.4.11 h1:FmREHJqOsKvLcsG6EuEWigXPG7F7PLN6kWwt9BD7OHM=
github.com/go-zoox/core-utils v1.4.11/go.mod h1:raOOwr2l2sJQyjR0Dg33sg0ry4U1/L2eNTuLFRpUXWs=
github.com/go-zoox/counter v1.0.1/go.mod h1:PICilZTrnO4dFstDPlXpjc6sdWYBG7hm/XDmjAcHaX0=
github.com/go-zoox/counter v1.2.0 h1:a1sMgYmnOza4UgjDD/fLs+HqTPG2Kh54v2IH41uIi7Q=
github.com/go-zoox/counter v1.2.0/go.mod h1:dCAErDaaxnnqQrfPNkJYklqSQrZ9SKzH3iiciJa3BH4=
Expand All @@ -67,6 +71,8 @@ github.com/go-zoox/crypto v1.1.8/go.mod h1:JqgNr9HcFFGQkMCGLJ9djtfg/RWVLxtunG01H
github.com/go-zoox/datetime v1.0.4/go.mod h1:os6lYW/GXNpCIseFrBr8DNcOiPuwl5Ttc/kxo4JnMjw=
github.com/go-zoox/datetime v1.1.1 h1:ORZbMuSLMW3KSV9dDaGf7iKL5XqYoIn9eQuK6QMeRDY=
github.com/go-zoox/datetime v1.1.1/go.mod h1:os6lYW/GXNpCIseFrBr8DNcOiPuwl5Ttc/kxo4JnMjw=
github.com/go-zoox/datetime v1.3.1 h1:HFyVtfgyLXwfJsLl0EjhaWTKt9s0QxTonb7s0JtJmVg=
github.com/go-zoox/datetime v1.3.1/go.mod h1:qvaCrzjhq/g/gstx4sx06Nl4ll2pLSrkRa9ueLjrZ9A=
github.com/go-zoox/debug v1.0.1 h1:lAsUnofJ1xWnfpHQQ6O5ss0xS0J+8LVAYbv+qiH0ARQ=
github.com/go-zoox/debug v1.0.1/go.mod h1:7HvnBeV1dVuuGVnXSLdJ5OE6X/wIXAjIEyiaA7NqQPA=
github.com/go-zoox/dotenv v1.0.7/go.mod h1:N2bXxghq3Zk+lpiOxv+m+0yjnGubVqJGJDR/9jWm3N0=
Expand All @@ -87,6 +93,8 @@ github.com/go-zoox/fs v1.2.4/go.mod h1:aywpClMqf6YO8+QnuwC3p3EvFWe88h0tWH65rpxtY
github.com/go-zoox/fs v1.2.5/go.mod h1:aywpClMqf6YO8+QnuwC3p3EvFWe88h0tWH65rpxtY00=
github.com/go-zoox/fs v1.3.13 h1:fe0uvtXCM+9s51z/CnQ5kxB4hBYaK55tkrE9gq0385U=
github.com/go-zoox/fs v1.3.13/go.mod h1:wCM+UQkjFTxNjOOCNlGcN3k9FeXXUwn9bFnpyjOn55c=
github.com/go-zoox/fs v1.3.15 h1:kHH1M0t9p96BES0p3aDakkCw8h9BjOyWSsHQ91IWmao=
github.com/go-zoox/fs v1.3.15/go.mod h1:GGcmvYa1Kyvspc8YzPt0peLGie+KlCoo2gkg4XbGRiY=
github.com/go-zoox/gzip v1.0.0 h1:11ZTgxAPgexmZ/NJaEEuN2FDCJuvg9sips+XDR+48Yw=
github.com/go-zoox/gzip v1.0.0/go.mod h1:7g9vTpKek1dft1Yi1Ryi4A6dq9snMgq94Qq8wSte8L0=
github.com/go-zoox/headers v1.0.8 h1:HZJisMHhKwdySVNbV4Awc5kaMxFfAwBIHpcWOGch+iw=
Expand All @@ -109,6 +117,8 @@ github.com/go-zoox/kv v1.5.1/go.mod h1:u/IbVscKbZk4AyDvvnsK9DiaWshH/Nz3twlGDRyC9
github.com/go-zoox/logger v1.2.0/go.mod h1:mBImRV6zpbGtiIjDz/C9vWi80wWc2OTOl9N9P0SAJgk=
github.com/go-zoox/logger v1.4.5 h1:HHNJNiNDA6c4T/pu9EJup85In+5ZF5SYEjqMvEEqnYU=
github.com/go-zoox/logger v1.4.5/go.mod h1:o7ddvv/gMoMa0TomPhHoIz11ZWRbQ92pF6rwYbOY3iQ=
github.com/go-zoox/logger v1.5.1 h1:mAACnHGxSD27bAw/xjkJp7PLlTGBkSBRQPFoEWXe+EM=
github.com/go-zoox/logger v1.5.1/go.mod h1:o7ddvv/gMoMa0TomPhHoIz11ZWRbQ92pF6rwYbOY3iQ=
github.com/go-zoox/proxy v1.2.3/go.mod h1:T+gbngAtIgvambbYibAbzrjwdu8j5pduJdA2j6RYi94=
github.com/go-zoox/proxy v1.5.1 h1:P5RH8evyNOP2ws4oi2A4FcNkBtoElP4mudxuzAU7h+8=
github.com/go-zoox/proxy v1.5.1/go.mod h1:KLWeJqfQk1upCvEdXt3tEuM8xSu0ApbA9FNLOmyHysY=
Expand Down Expand Up @@ -156,6 +166,8 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
Expand Down Expand Up @@ -225,6 +237,8 @@ github.com/sevlyar/go-daemon v0.1.6/go.mod h1:6dJpPatBT9eUwM5VCw9Bt6CdX9Tk6UWvhW
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA=
github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48=
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
Expand Down Expand Up @@ -302,6 +316,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
21 changes: 17 additions & 4 deletions watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os/exec"
"regexp"

"github.com/go-zoox/core-utils/array"
"github.com/go-zoox/fs"
"github.com/go-zoox/logger"
"github.com/go-zoox/watch/process"
Expand All @@ -33,6 +34,7 @@ type Config struct {
Context string
Paths []string
Ignores []string
Exts []string
Env map[string]string
// go | golang
Mode string
Expand Down Expand Up @@ -83,7 +85,7 @@ func (w *watcher) Watch() error {
`, w.cfg.Commands, w.cfg.Context)
if err := w.run(); err != nil {
logger.Error("failed to run processes: %s", err)
logger.Errorf("failed to run processes: %s", err)
}
}()

Expand All @@ -96,7 +98,7 @@ func (w *watcher) Watch() error {
ignored := false
for _, ignore := range w.cfg.Ignores {
if ok, err := regexp.MatchString(ignore, filepath); err != nil {
logger.Error("failed to match ignore: %s (err: %s)", ignore, err)
logger.Errorf("failed to match ignore: %s (err: %s)", ignore, err)
return
} else if ok {
ignored = true
Expand All @@ -107,16 +109,27 @@ func (w *watcher) Watch() error {
return
}

// check ext, if not match anyone, ignore
if len(w.cfg.Exts) > 0 {
vExt := fs.ExtName(filepath)
ok := array.Some(w.cfg.Exts, func(element string, index int) bool {
return element == vExt
})
if !ok {
return
}
}

logger.Infof("[watch] file changes, restart processes (event: %s) ...", event)
if err := w.restart(); err != nil {
logger.Error("[watch] failed to restart processes: %s", err)
logger.Errorf("[watch] failed to restart processes: %s", err)
}
})
if err != nil {
return fmt.Errorf("failed to create watcher: %s", err)
}

logger.Info("[watch] stopping ...")
logger.Infof("[watch] stopping ...")
return nil
}

Expand Down

0 comments on commit 54bce94

Please sign in to comment.