diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md new file mode 100644 index 0000000..8c71bf6 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# GW (Go Watcher) + +## Stacks + +Built in Go + +## Features + +re-Run the command in case of any changes in project directory + +## How to use + +## Next to do diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..0fdab04 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module github.com/mattdamon108/gomon + +go 1.12 + +require ( + github.com/fsnotify/fsnotify v1.4.7 + golang.org/x/sys v0.0.0-20190508220229-2d0786266e9c // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..c36cb4e --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +golang.org/x/sys v0.0.0-20190508220229-2d0786266e9c h1:hDn6jm7snBX2O7+EeTk6Q4WXJfKt7MWgtiCCRi1rBoY= +golang.org/x/sys v0.0.0-20190508220229-2d0786266e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/main.go b/main.go new file mode 100644 index 0000000..3484d31 --- /dev/null +++ b/main.go @@ -0,0 +1,61 @@ +package main + +import ( + // "fmt" + "log" + "os" + "os/exec" + + "github.com/fsnotify/fsnotify" +) + +func runTest() *exec.Cmd { + p := exec.Command("./test-run") + p.Stdout = os.Stdout + p.Stderr = os.Stderr + p.Dir = "." + p.Start() + + return p +} + +func main() { + watcher, err := fsnotify.NewWatcher() + if err != nil { + log.Fatal(err) + } + defer watcher.Close() + + p := runTest() + + done := make(chan bool) + go func() { + for { + select { + case event, ok := <-watcher.Events: + if !ok { + return + } + log.Println("event: ", event) + if event.Op&fsnotify.Write == fsnotify.Write { + log.Println("modified file: ", event.Name) + } + p.Process.Kill() + + p = runTest() + case err, ok := <-watcher.Errors: + if !ok { + return + } + log.Println("error: ", err) + } + } + }() + + err = watcher.Add(".") + if err != nil { + log.Fatal(err) + } + + <-done +} diff --git a/runner/runner.go b/runner/runner.go new file mode 100644 index 0000000..a77b80e --- /dev/null +++ b/runner/runner.go @@ -0,0 +1,18 @@ +package main + +import ( + "log" +) + +func main() { + log.Println("I'm running...") + + done := make(chan bool) + + go func() { + for { + } + }() + + <-done +} diff --git a/test-run b/test-run new file mode 100755 index 0000000..5b797e0 Binary files /dev/null and b/test-run differ