github.com/wawandco/oxpecker-plugins@v0.1.1/tools/refresh/dev.go (about) 1 package refresh 2 3 import ( 4 "context" 5 "os" 6 "path/filepath" 7 "time" 8 9 "github.com/markbates/refresh/refresh" 10 "github.com/wawandco/oxpecker-plugins/internal/info" 11 ) 12 13 func (w Plugin) Develop(ctx context.Context, root string) error { 14 config, err := w.config(root) 15 if err != nil { 16 return err 17 } 18 19 r := refresh.NewWithContext(config, ctx) 20 return r.Start() 21 } 22 23 // config tries to pull the config from .buffalo.dev.yml otherwise uses default config 24 func (w Plugin) config(root string) (*refresh.Configuration, error) { 25 c := &refresh.Configuration{} 26 if _, err := os.Stat(".buffalo.dev.yml"); err == nil { 27 err = c.Load(".buffalo.dev.yml") 28 return c, err 29 } 30 31 return w.defaultConfig(root) 32 } 33 34 func (w Plugin) defaultConfig(root string) (*refresh.Configuration, error) { 35 name, err := info.BuildName() 36 if err != nil { 37 return nil, err 38 } 39 40 config := &refresh.Configuration{ 41 IgnoredFolders: []string{ 42 "vendor", 43 "log", 44 "logs", 45 "webpack", 46 "public", 47 "grifts", 48 "tmp", 49 "bin", 50 "node_modules", 51 ".sass-cache", 52 }, 53 54 IncludedExtensions: []string{ 55 ".go", 56 ".mod", 57 ".env", 58 }, 59 60 BuildPath: "tmp", 61 BuildDelay: 200 * time.Millisecond, 62 EnableColors: true, 63 LogName: "x", 64 65 // BuildFlags: bflags, 66 67 AppRoot: root, 68 BinaryName: name + "-build", 69 BuildTargetPath: filepath.Join(root, "cmd", name), 70 } 71 72 return config, nil 73 }