better routines workflow
This commit is contained in:
parent
21045786c5
commit
5981ff06f2
|
@ -53,6 +53,10 @@ func LogSuccess(msg string) {
|
|||
log.Println(green(msg))
|
||||
}
|
||||
|
||||
func LogFail(msg string) {
|
||||
log.Println(red(msg))
|
||||
}
|
||||
|
||||
func (app *App) Information() {
|
||||
fmt.Println(blue(app.Name) + " - " + blue(app.Version))
|
||||
fmt.Println(bluel(app.Description) + "\n")
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"bytes"
|
||||
"bufio"
|
||||
"log"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Project struct {
|
||||
|
@ -20,11 +21,15 @@ type Project struct {
|
|||
Watcher Watcher `yaml:"app_watcher,omitempty"`
|
||||
}
|
||||
|
||||
func (p *Project) GoRun(channel chan bool) error {
|
||||
func (p *Project) GoRun(channel chan bool, wr *sync.WaitGroup) error {
|
||||
base, _ := os.Getwd()
|
||||
build := exec.Command("go", "run", p.Main)
|
||||
path := base + p.Path
|
||||
build.Dir = path
|
||||
defer func() {
|
||||
LogFail(p.Name + ": Stopped")
|
||||
wr.Done()
|
||||
}()
|
||||
|
||||
stdout, err := build.StdoutPipe()
|
||||
if err != nil {
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Watcher struct {
|
||||
|
@ -37,8 +38,9 @@ func (h *Config) Watch() error {
|
|||
|
||||
func (p *Project) Watching() {
|
||||
|
||||
channel := make(chan bool,1)
|
||||
var wr sync.WaitGroup
|
||||
var watcher *fsnotify.Watcher
|
||||
channel := make(chan bool)
|
||||
watcher, _ = fsnotify.NewWatcher()
|
||||
defer func() {
|
||||
watcher.Close()
|
||||
|
@ -58,6 +60,11 @@ func (p *Project) Watching() {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
routines := func(){
|
||||
channel = make(chan bool)
|
||||
wr.Add(1)
|
||||
go p.build(); p.install(); p.run(channel, &wr);
|
||||
}
|
||||
|
||||
for _, dir := range p.Watcher.Paths {
|
||||
base, _ := os.Getwd()
|
||||
|
@ -83,8 +90,7 @@ func (p *Project) Watching() {
|
|||
}
|
||||
}
|
||||
|
||||
// go build, install, run
|
||||
go p.build(); p.install(); p.run(channel);
|
||||
routines()
|
||||
|
||||
fmt.Println(red("\n Watching: '" + p.Name + "'\n"))
|
||||
|
||||
|
@ -103,8 +109,8 @@ func (p *Project) Watching() {
|
|||
|
||||
// stop and run again
|
||||
close(channel)
|
||||
channel = make(chan bool)
|
||||
go p.build(); p.install(); p.run(channel);
|
||||
wr.Wait()
|
||||
routines()
|
||||
|
||||
p.reload = time.Now().Truncate(time.Second)
|
||||
}
|
||||
|
@ -143,10 +149,10 @@ func (p *Project) build() {
|
|||
return
|
||||
}
|
||||
|
||||
func (p *Project) run(channel chan bool) {
|
||||
func (p *Project) run(channel chan bool, wr *sync.WaitGroup) {
|
||||
if p.Run {
|
||||
LogSuccess(p.Name + ": Running..")
|
||||
go p.GoRun(channel)
|
||||
go p.GoRun(channel, wr)
|
||||
LogSuccess(p.Name + ": Runned")
|
||||
}
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue