diff --git a/.gitignore b/.gitignore index 0b80971e2f3..1c8cc1fb07f 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,9 @@ cmd/gf/gf temp/ go.work go.work.sum -!cmd/gf/go.work \ No newline at end of file +!cmd/gf/go.work + +# Ignore for docs +node_modules +.docusaurus +output diff --git a/cmd/gf/internal/cmd/cmd_run.go b/cmd/gf/internal/cmd/cmd_run.go index 337ba7aa697..5f242abbd10 100644 --- a/cmd/gf/internal/cmd/cmd_run.go +++ b/cmd/gf/internal/cmd/cmd_run.go @@ -99,6 +99,7 @@ func (c cRun) Index(ctx context.Context, in cRunInput) (out *cRunOutput, err err if len(in.WatchPaths) == 1 { in.WatchPaths = strings.Split(in.WatchPaths[0], ",") + mlog.Printf("watchPaths: %v", in.WatchPaths) } app := &cRunApp{ @@ -109,8 +110,9 @@ func (c cRun) Index(ctx context.Context, in cRunInput) (out *cRunOutput, err err WatchPaths: in.WatchPaths, } dirty := gtype.NewBool() - _, err = gfsnotify.Add(gfile.RealPath("."), func(event *gfsnotify.Event) { - if gfile.ExtName(event.Path) != "go" && !matchWatchPaths(app.WatchPaths, event.Path) { + + callbackFunc := func(event *gfsnotify.Event) { + if gfile.ExtName(event.Path) != "go" { return } @@ -125,10 +127,22 @@ func (c cRun) Index(ctx context.Context, in cRunInput) (out *cRunOutput, err err mlog.Printf(`watched file changes: %s`, event.String()) app.Run(ctx) }) - }) - if err != nil { - mlog.Fatal(err) } + + if len(app.WatchPaths) > 0 { + for _, path := range app.WatchPaths { + _, err = gfsnotify.Add(gfile.RealPath(path), callbackFunc) + if err != nil { + mlog.Fatal(err) + } + } + } else { + _, err = gfsnotify.Add(gfile.RealPath("."), callbackFunc) + if err != nil { + mlog.Fatal(err) + } + } + go app.Run(ctx) select {} }