|
|
|
|
@ -6,11 +6,14 @@ import ( |
|
|
|
|
"log" |
|
|
|
|
"io" |
|
|
|
|
"os" |
|
|
|
|
"io/fs" |
|
|
|
|
"path/filepath" |
|
|
|
|
"errors" |
|
|
|
|
"lcthw.dev/go/ttarpit/config" |
|
|
|
|
"sync" |
|
|
|
|
"github.com/fsnotify/fsnotify" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func LaunchLogger(in io.Reader, out io.Writer, err error) { |
|
|
|
|
if err != nil { log.Fatal(err) } |
|
|
|
|
|
|
|
|
|
@ -50,11 +53,7 @@ func LaunchProcess(proc *config.Process) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
|
config.Load() |
|
|
|
|
|
|
|
|
|
var wg sync.WaitGroup |
|
|
|
|
|
|
|
|
|
func RunBuild() { |
|
|
|
|
fmt.Println("CONFIG:", config.Settings.ConfigPath) |
|
|
|
|
fmt.Println("COMMANDs:", config.Settings.Processes) |
|
|
|
|
|
|
|
|
|
@ -62,11 +61,76 @@ func main() { |
|
|
|
|
fmt.Println("PROCESS:", name) |
|
|
|
|
|
|
|
|
|
proc.Ready = make(chan string) |
|
|
|
|
wg.Go(func() { |
|
|
|
|
LaunchProcess(&proc) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func AddWatchDir(watcher *fsnotify.Watcher, name string) error { |
|
|
|
|
return filepath.WalkDir(name, |
|
|
|
|
func(path string, d fs.DirEntry, err error) error { |
|
|
|
|
if err != nil { |
|
|
|
|
log.Printf("WATCH ERROR! walking=%s path=%s: err=%v", name, path, err) |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if d.IsDir() { |
|
|
|
|
log.Println("WATCHING: ", path) |
|
|
|
|
err = watcher.Add(path) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Printf("failed to watch %s", path) |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func WatchDir() { |
|
|
|
|
watcher, err := fsnotify.NewWatcher() |
|
|
|
|
if err != nil { |
|
|
|
|
log.Fatal("Failed to start fsnotify", err) |
|
|
|
|
} |
|
|
|
|
defer watcher.Close() |
|
|
|
|
|
|
|
|
|
go func() { |
|
|
|
|
for { |
|
|
|
|
select { |
|
|
|
|
case event, ok := <-watcher.Events: |
|
|
|
|
if !ok { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if event.Has(fsnotify.Create) { |
|
|
|
|
log.Println("---> CREATE", event.Name) |
|
|
|
|
// ADD DIR
|
|
|
|
|
} else { |
|
|
|
|
log.Println("event:", event) |
|
|
|
|
} |
|
|
|
|
// check if match then do thing
|
|
|
|
|
go RunBuild() |
|
|
|
|
case err, ok := <-watcher.Errors: |
|
|
|
|
if !ok { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
log.Println("error: ", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}() |
|
|
|
|
|
|
|
|
|
err = AddWatchDir(watcher, ".") |
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
log.Fatal(err, "Failed to watch .") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
<-make(chan struct{}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
|
config.Load() |
|
|
|
|
|
|
|
|
|
fmt.Println("WAITING....") |
|
|
|
|
wg.Wait() |
|
|
|
|
WatchDir() |
|
|
|
|
} |
|
|
|
|
|