start/stop workflow improved

This commit is contained in:
alessio 2016-08-19 22:52:53 +02:00
parent 19d0b04c73
commit dfec8209f3
3 changed files with 19 additions and 33 deletions

View File

@ -43,6 +43,7 @@ func New(params *cli.Context) *Config {
func Duplicates(value Project, arr []Project) bool { func Duplicates(value Project, arr []Project) bool {
for _, val := range arr { for _, val := range arr {
if value.Main == val.Main && value.Path == val.Path || value.Name == val.Name { 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 return true
} }
} }
@ -109,6 +110,7 @@ func (h *Config) Add(params *cli.Context) error {
Path: params.String("base"), Path: params.String("base"),
Run: params.Bool("run"), Run: params.Bool("run"),
Build: params.Bool("build"), Build: params.Bool("build"),
Bin: params.Bool("bin"),
Watcher: Watcher{ Watcher: Watcher{
Paths: watcherPaths, Paths: watcherPaths,
Exts: watcherExts, Exts: watcherExts,

View File

@ -33,7 +33,7 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
if len(name) == 1 { if len(name) == 1 {
name := strings.Split(p.base, "/") name := strings.Split(p.base, "/")
run = name[len(name)-1] run = name[len(name)-1]
} else { }else {
run = name[len(name)-1] run = name[len(name)-1]
} }
build := exec.Command(os.Getenv("GOPATH") + slash("bin") + slash(run)) 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() { for in.Scan() {
select { select {
default: default:
log.Println(p.Name+":", in.Text()) log.Println(bluel(p.Name+":"), bluel(in.Text()))
} }
} }
close(stop) close(stop)

View File

@ -70,16 +70,12 @@ func (p *Project) Watching() {
channel = make(chan bool) channel = make(chan bool)
wr.Add(1) wr.Add(1)
go p.build() go p.build()
go p.install(&wr) go p.install(channel,&wr)
wr.Wait()
wr.Add(1)
p.run(channel, &wr)
} }
end := func() { end := func() {
watcher.Close() watcher.Close()
wg.Done() wg.Done()
} }
defer end() defer end()
p.Main = slash(p.Main) p.Main = slash(p.Main)
@ -103,11 +99,8 @@ func (p *Project) Watching() {
} }
} }
routines() routines()
fmt.Println(red("\n Watching: '" + p.Name + "'\n")) fmt.Println(red("\n Watching: '" + p.Name + "'\n"))
p.reload = time.Now().Truncate(time.Second) p.reload = time.Now().Truncate(time.Second)
for { for {
select { select {
case event := <-watcher.Events: case event := <-watcher.Events:
@ -134,16 +127,28 @@ func (p *Project) Watching() {
} }
// Install call an implementation of the "go install" // 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 { if p.Bin {
LogSuccess(p.Name + ": Installing..") LogSuccess(p.Name + ": Installing..")
if err := p.GoInstall(); err != nil { if err := p.GoInstall(); err != nil {
Fail(err.Error()) Fail(err.Error())
wr.Done()
} else { } else {
LogSuccess(p.Name + ": Installed") 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 return
} }
@ -161,27 +166,6 @@ func (p *Project) build() {
return 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 // Ignore validates a path
func (p *Project) ignore(str string) bool { func (p *Project) ignore(str string) bool {
for _, v := range p.Watcher.Ignore { for _, v := range p.Watcher.Ignore {