diff --git a/cli/cmd.go b/cli/cmd.go index 66dcca5..27e277e 100644 --- a/cli/cmd.go +++ b/cli/cmd.go @@ -15,9 +15,9 @@ func (h *Blueprint) Run() error { if err == nil { // loop projects wg.Add(len(h.Projects)) - for _, v := range h.Projects { - v.parent = h - go v.watching() + for k := range h.Projects { + h.Projects[k].parent = h + go h.Projects[k].watching() } wg.Wait() return nil diff --git a/cli/exec.go b/cli/exec.go index b761bd6..5c9ca6c 100644 --- a/cli/exec.go +++ b/cli/exec.go @@ -29,10 +29,10 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup) build.Dir = p.base defer func() { if err := build.Process.Kill(); err != nil { - p.Buffer.StdLog = append(p.Buffer.StdLog, "Failed to stop: "+err.Error()) + p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Failed to stop: " + err.Error()}) log.Fatal(Red("Failed to stop: "), Red(err)) } - p.Buffer.StdLog = append(p.Buffer.StdLog, "Ended") + p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Ended"}) log.Println(pname(p.Name, 2), ":", RedS("Ended")) go sync() wr.Done() @@ -59,9 +59,9 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup) select { default: if isError { - p.Buffer.StdErr = append(p.Buffer.StdErr, output.Text()) + p.Buffer.StdErr = append(p.Buffer.StdErr, BufferOut{Time: time.Now(), Text: output.Text()}) } else { - p.Buffer.StdOut = append(p.Buffer.StdOut, output.Text()) + p.Buffer.StdOut = append(p.Buffer.StdOut, BufferOut{Time: time.Now(), Text: output.Text()}) } go sync() @@ -80,6 +80,7 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup) } close(stop) } + p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Started"}) go scanner(stopOutput, execOutput, false) go scanner(stopError, execError, true) diff --git a/cli/main.go b/cli/main.go index 44ebb34..b0e4b83 100644 --- a/cli/main.go +++ b/cli/main.go @@ -26,12 +26,12 @@ type logWriter struct{} type Blueprint struct { Projects []Project `yaml:"projects,omitempty"` Files map[string]string `yaml:"-"` - Sync chan string + Sync chan string `yaml:"-"` } // Project defines the informations of a single project type Project struct { - LastChangedOn time.Time + LastChangedOn time.Time `yaml:"-"` base string Name string `yaml:"app_name,omitempty"` Path string `yaml:"app_path,omitempty"` @@ -60,9 +60,14 @@ type Watcher struct { // Buffer struct for buffering outputs type Buffer struct { - StdOut []string - StdLog []string - StdErr []string + StdOut []BufferOut + StdLog []BufferOut + StdErr []BufferOut +} + +type BufferOut struct { + Time time.Time + Text string } // Initialize the application diff --git a/cli/watcher.go b/cli/watcher.go index 96c0db8..cffc98f 100644 --- a/cli/watcher.go +++ b/cli/watcher.go @@ -18,6 +18,8 @@ import ( // Watching method is the main core. It manages the livereload and the watching func (p *Project) watching() { + log.Println(p) + var wr sync.WaitGroup var watcher *fsnotify.Watcher