|
|
|
@ -6,6 +6,9 @@ import ( |
|
|
|
"log" |
|
|
|
"log" |
|
|
|
"io" |
|
|
|
"io" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
|
|
|
|
"time" |
|
|
|
|
|
|
|
"slices" |
|
|
|
|
|
|
|
"regexp" |
|
|
|
"io/fs" |
|
|
|
"io/fs" |
|
|
|
"path/filepath" |
|
|
|
"path/filepath" |
|
|
|
"errors" |
|
|
|
"errors" |
|
|
|
@ -13,7 +16,6 @@ import ( |
|
|
|
"github.com/fsnotify/fsnotify" |
|
|
|
"github.com/fsnotify/fsnotify" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func LaunchLogger(in io.Reader, out io.Writer, err error) { |
|
|
|
func LaunchLogger(in io.Reader, out io.Writer, err error) { |
|
|
|
if err != nil { log.Fatal(err) } |
|
|
|
if err != nil { log.Fatal(err) } |
|
|
|
|
|
|
|
|
|
|
|
@ -25,7 +27,6 @@ func LaunchLogger(in io.Reader, out io.Writer, err error) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func LaunchProcess(proc *config.Process) { |
|
|
|
func LaunchProcess(proc *config.Process) { |
|
|
|
for { |
|
|
|
|
|
|
|
proc.ExecCmd = exec.Command(proc.Command, proc.Args...) |
|
|
|
proc.ExecCmd = exec.Command(proc.Command, proc.Args...) |
|
|
|
if errors.Is(proc.ExecCmd.Err, exec.ErrDot) { |
|
|
|
if errors.Is(proc.ExecCmd.Err, exec.ErrDot) { |
|
|
|
proc.ExecCmd.Err = nil |
|
|
|
proc.ExecCmd.Err = nil |
|
|
|
@ -47,21 +48,46 @@ func LaunchProcess(proc *config.Process) { |
|
|
|
fmt.Println("WAITING for", proc.Command) |
|
|
|
fmt.Println("WAITING for", proc.Command) |
|
|
|
|
|
|
|
|
|
|
|
fmt.Println("SENDING READY on channel") |
|
|
|
fmt.Println("SENDING READY on channel") |
|
|
|
proc.Ready<- "ready" |
|
|
|
|
|
|
|
|
|
|
|
fmt.Println("SENT READY") |
|
|
|
proc.ExecCmd.Wait() |
|
|
|
proc.ExecCmd.Wait() |
|
|
|
fmt.Println("PROCESS", proc.Command, "EXITED") |
|
|
|
fmt.Println("PROCESS", proc.Command, "EXITED") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func MatchesPath(fp string) bool { |
|
|
|
|
|
|
|
fp = filepath.ToSlash(fp) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
is_included := slices.ContainsFunc(config.Settings.Includes, func (reg string) bool { |
|
|
|
|
|
|
|
matches, err := regexp.MatchString(reg, fp) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Panic("invalid excludes regex", reg, "error: ", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return matches |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return is_included |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func RunBuild() { |
|
|
|
func RunBuild() { |
|
|
|
|
|
|
|
if !config.Settings.BuildRunning { |
|
|
|
|
|
|
|
config.Settings.BuildRunning = true |
|
|
|
|
|
|
|
defer func(){config.Settings.BuildRunning = false}() |
|
|
|
|
|
|
|
|
|
|
|
fmt.Println("CONFIG:", config.Settings.ConfigPath) |
|
|
|
fmt.Println("CONFIG:", config.Settings.ConfigPath) |
|
|
|
fmt.Println("COMMANDs:", config.Settings.Processes) |
|
|
|
fmt.Println("COMMANDs:", config.Settings.Processes) |
|
|
|
|
|
|
|
|
|
|
|
for name, proc := range config.Settings.Processes { |
|
|
|
for name, proc := range config.Settings.Processes { |
|
|
|
fmt.Println("PROCESS:", name) |
|
|
|
fmt.Println("PROCESS:", name) |
|
|
|
|
|
|
|
|
|
|
|
proc.Ready = make(chan string) |
|
|
|
|
|
|
|
LaunchProcess(&proc) |
|
|
|
LaunchProcess(&proc) |
|
|
|
|
|
|
|
fmt.Println("=================== PROCESS EXIT") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
time.Sleep(1000 * time.Millisecond) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
fmt.Println("!!!! BUILD SKIP, already running") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -103,12 +129,15 @@ func WatchDir() { |
|
|
|
|
|
|
|
|
|
|
|
if event.Has(fsnotify.Create) { |
|
|
|
if event.Has(fsnotify.Create) { |
|
|
|
log.Println("---> CREATE", event.Name) |
|
|
|
log.Println("---> CREATE", event.Name) |
|
|
|
// ADD DIR
|
|
|
|
AddWatchDir(watcher, event.Name) |
|
|
|
|
|
|
|
} else if event.Has(fsnotify.Write) { |
|
|
|
|
|
|
|
// check if match then do thing
|
|
|
|
|
|
|
|
if MatchesPath(event.Name) { |
|
|
|
|
|
|
|
go RunBuild() |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
log.Println("event:", event) |
|
|
|
log.Println("event:", event) |
|
|
|
} |
|
|
|
} |
|
|
|
// check if match then do thing
|
|
|
|
|
|
|
|
go RunBuild() |
|
|
|
|
|
|
|
case err, ok := <-watcher.Errors: |
|
|
|
case err, ok := <-watcher.Errors: |
|
|
|
if !ok { |
|
|
|
if !ok { |
|
|
|
return |
|
|
|
return |
|
|
|
|