Compare commits

...

2 Commits

Author SHA1 Message Date
ea1d5ea911 Merge remote-tracking branch 'origin/master' 2022-02-01 17:16:01 +01:00
12de91324e Add -c param and exclusion 2022-02-01 17:15:14 +01:00
2 changed files with 39 additions and 20 deletions

34
main.go
View File

@ -23,6 +23,7 @@ type options struct {
ESBuild api.BuildOptions ESBuild api.BuildOptions
Watch struct { Watch struct {
Path string Path string
Exclude []string
} }
Copy []struct { Copy []struct {
Src string Src string
@ -31,8 +32,22 @@ type options struct {
} }
func main() { func main() {
flow := &goyek.Flow{}
opts := options{} opts := options{}
cfgContent, err := os.ReadFile("./.gowebbuild.json")
cfgPathParam := flow.RegisterStringParam(goyek.StringParam{
Name: "c",
Usage: "Path to config file config file.",
Default: "./.gowebbuild.json",
})
watchFrontend := goyek.Task{
Name: "watch-frontend",
Usage: "",
Params: goyek.Params{cfgPathParam},
Action: func(tf *goyek.TF) {
cfgPath := cfgPathParam.Get(tf)
cfgContent, err := os.ReadFile(cfgPath)
if err != nil { if err != nil {
fmt.Printf("%+v\n", err) fmt.Printf("%+v\n", err)
@ -45,12 +60,6 @@ func main() {
os.Exit(1) os.Exit(1)
} }
flow := &goyek.Flow{}
flow.Register(goyek.Task{
Name: "watch-frontend",
Usage: "",
Action: func(tf *goyek.TF) {
c := make(chan os.Signal, 1) c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM) signal.Notify(c, os.Interrupt, syscall.SIGTERM)
@ -60,6 +69,11 @@ func main() {
w := watcher.New() w := watcher.New()
w.SetMaxEvents(1) w.SetMaxEvents(1)
w.FilterOps(watcher.Write, watcher.Rename, watcher.Move, watcher.Create, watcher.Remove) w.FilterOps(watcher.Write, watcher.Rename, watcher.Move, watcher.Create, watcher.Remove)
if len(opts.Watch.Exclude) > 0 {
w.Ignore(opts.Watch.Exclude...)
}
if err := w.AddRecursive(opts.Watch.Path); err != nil { if err := w.AddRecursive(opts.Watch.Path); err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
os.Exit(1) os.Exit(1)
@ -82,6 +96,9 @@ func main() {
fmt.Printf("Watching %d elements in %s\n", len(w.WatchedFiles()), opts.Watch.Path) fmt.Printf("Watching %d elements in %s\n", len(w.WatchedFiles()), opts.Watch.Path)
cp(opts)
build(opts)
if err := w.Start(time.Millisecond * 100); err != nil { if err := w.Start(time.Millisecond * 100); err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
} }
@ -108,8 +125,9 @@ func main() {
fmt.Println("\nExit") fmt.Println("\nExit")
os.Exit(0) os.Exit(0)
}, },
}) }
flow.DefaultTask = flow.Register(watchFrontend)
flow.Main() flow.Main()
} }

View File

@ -1,6 +1,7 @@
{ {
"Watch": { "Watch": {
"Path": "./frontend/src" "Path": "./frontend/src",
"Exclude": [ "./dist" ]
}, },
"Copy": [ "Copy": [
{ {