From dfec8209f3c7c108e2be715fe53665bc3ba7a2ba Mon Sep 17 00:00:00 2001 From: alessio Date: Fri, 19 Aug 2016 22:52:53 +0200 Subject: [PATCH] start/stop workflow improved --- realize/config.go | 2 ++ realize/project.go | 4 ++-- realize/watcher.go | 46 +++++++++++++++------------------------------- 3 files changed, 19 insertions(+), 33 deletions(-) diff --git a/realize/config.go b/realize/config.go index fdfe9ac..10f0bb5 100644 --- a/realize/config.go +++ b/realize/config.go @@ -43,6 +43,7 @@ func New(params *cli.Context) *Config { func Duplicates(value Project, arr []Project) bool { for _, val := range arr { if value.Main == val.Main && value.Path == val.Path || value.Name == val.Name { + Fail("There is a duplicate of '"+val.Name+"'. Check your config file!") return true } } @@ -109,6 +110,7 @@ func (h *Config) Add(params *cli.Context) error { Path: params.String("base"), Run: params.Bool("run"), Build: params.Bool("build"), + Bin: params.Bool("bin"), Watcher: Watcher{ Paths: watcherPaths, Exts: watcherExts, diff --git a/realize/project.go b/realize/project.go index e91d3c4..c8594b6 100644 --- a/realize/project.go +++ b/realize/project.go @@ -33,7 +33,7 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup) if len(name) == 1 { name := strings.Split(p.base, "/") run = name[len(name)-1] - } else { + }else { run = name[len(name)-1] } build := exec.Command(os.Getenv("GOPATH") + slash("bin") + slash(run)) @@ -60,7 +60,7 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup) for in.Scan() { select { default: - log.Println(p.Name+":", in.Text()) + log.Println(bluel(p.Name+":"), bluel(in.Text())) } } close(stop) diff --git a/realize/watcher.go b/realize/watcher.go index 7e9f91e..c06170a 100644 --- a/realize/watcher.go +++ b/realize/watcher.go @@ -70,16 +70,12 @@ func (p *Project) Watching() { channel = make(chan bool) wr.Add(1) go p.build() - go p.install(&wr) - wr.Wait() - wr.Add(1) - p.run(channel, &wr) + go p.install(channel,&wr) } end := func() { watcher.Close() wg.Done() } - defer end() p.Main = slash(p.Main) @@ -103,11 +99,8 @@ func (p *Project) Watching() { } } routines() - fmt.Println(red("\n Watching: '" + p.Name + "'\n")) - p.reload = time.Now().Truncate(time.Second) - for { select { case event := <-watcher.Events: @@ -134,16 +127,28 @@ func (p *Project) Watching() { } // Install call an implementation of the "go install" -func (p *Project) install(wr *sync.WaitGroup) { +func (p *Project) install(channel chan bool,wr *sync.WaitGroup) { if p.Bin { LogSuccess(p.Name + ": Installing..") if err := p.GoInstall(); err != nil { Fail(err.Error()) + wr.Done() } else { LogSuccess(p.Name + ": Installed") + if p.Run { + runner := make(chan bool, 1) + LogSuccess(p.Name + ": Running..") + go p.GoRun(channel, runner, wr) + for { + select { + case <-runner: + LogSuccess(p.Name + ": Runned") + return + } + } + } } } - wr.Done() return } @@ -161,27 +166,6 @@ func (p *Project) build() { return } -// Build call an implementation of the bin execution -func (p *Project) run(channel chan bool, wr *sync.WaitGroup) { - if p.Run { - if p.Bin { - runner := make(chan bool, 1) - LogSuccess(p.Name + ": Running..") - go p.GoRun(channel, runner, wr) - for { - select { - case <-runner: - LogSuccess(p.Name + ": Runned") - return - } - } - } else { - LogFail("Set 'app_run' to true for launch run") - } - } - return -} - // Ignore validates a path func (p *Project) ignore(str string) bool { for _, v := range p.Watcher.Ignore {