refactor(cmd/gf): Optimize run command to reload only on file write events (#4476)

优化run命令使得只在文件有写入事件时才触发reload:
gf run 的文件监控逻辑之前会对所有文件系统事件做出响应,包括非内容修改的事件(如文件access
time变化),这会导致开发过程中不必要的频繁重载。本次修改在文件监控回调中增加了event.IsWrite()的判断,确保只有在文件内容被实际写入时才触发重载逻辑,优化了开发体验。
This commit is contained in:
XG
2025-10-16 16:20:24 +08:00
committed by GitHub
parent 8ff0de88b8
commit 1d4e684949

View File

@ -27,9 +27,7 @@ import (
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
)
var (
Run = cRun{}
)
var Run = cRun{}
type cRun struct {
g.Meta `name:"run" usage:"{cRunUsage}" brief:"{cRunBrief}" eg:"{cRunEg}" dc:"{cRunDc}"`
@ -63,9 +61,7 @@ which compiles and runs the go codes asynchronously when codes change.
cRunWatchPathsBrief = `watch additional paths for live reload, separated by ",". i.e. "manifest/config/*.yaml"`
)
var (
process *gproc.Process
)
var process *gproc.Process
func init() {
gtag.Sets(g.MapStrStr{
@ -119,8 +115,12 @@ func (c cRun) Index(ctx context.Context, in cRunInput) (out *cRunOutput, err err
}
dirty := gtype.NewBool()
var outputPath = app.genOutputPath()
outputPath := app.genOutputPath()
callbackFunc := func(event *gfsnotify.Event) {
if !event.IsWrite() && !event.IsCreate() && !event.IsRemove() && !event.IsRename() {
return
}
if gfile.ExtName(event.Path) != "go" {
return
}