base path for each project, build call

This commit is contained in:
alessio 2016-08-03 10:30:45 +02:00
parent 3868698296
commit 117c3a0726
1 changed files with 33 additions and 39 deletions

View File

@ -7,29 +7,17 @@ import (
"os" "os"
"log" "log"
"strings" "strings"
"sync"
"time" "time"
"bytes"
) )
var wg sync.WaitGroup type Watcher struct{
// different before and after on re-run?
func InArray(str string, list []string) bool{ Before []string `yaml:"before,omitempty"`
for _, v := range list { After []string `yaml:"after,omitempty"`
if v == str { Paths []string `yaml:"paths,omitempty"`
return true Ignore []string `yaml:"ignore_paths,omitempty"`
} Exts []string `yaml:"exts,omitempty"`
} Preview bool `yaml:"preview,omitempty"`
return false
}
func Ignore(str string, list []string) bool{
for _, v := range list {
if strings.Contains(str, v) {
return true
}
}
return false
} }
func (p *Project) Watching(){ func (p *Project) Watching(){
@ -56,37 +44,25 @@ func (p *Project) Watching(){
} }
// run, bin, build // run, bin, build
p.GoBuild()
p.reload = time.Now().Truncate(time.Second) p.reload = time.Now().Truncate(time.Second)
for _, dir := range p.Watcher.Paths { for _, dir := range p.Watcher.Paths {
var base bytes.Buffer base, _ := os.Getwd()
path, _ := os.Getwd()
split := strings.Split(p.Main, "/")
// get base path from mail field // check path existence
for key, str := range split{ if _, err := os.Stat(base + p.Path + dir); err == nil {
if(key < len(split)-1) { if err := filepath.Walk(base + p.Path + dir, walk); err != nil {
base.WriteString("/" + str)
}
}
// add slash if doesn't exist
if string(dir[0]) != "/"{
dir = "/"+dir
}
if _, err := os.Stat(path + base.String() + dir); err == nil {
if err := filepath.Walk(path + base.String() + dir, walk); err != nil {
fmt.Println(err) fmt.Println(err)
} }
}else{ }else{
fmt.Println(red(p.Name + ": \t"+path + base.String() + dir +" doesn't exist")) fmt.Println(red(p.Name + ": \t"+base + p.Path + dir +" path doesn't exist"))
} }
} }
fmt.Println("\nWatching..\n") fmt.Println(red("Watching: '"+ p.Name +"'\n"))
for { for {
select { select {
@ -121,3 +97,21 @@ func (h *Config) Watch() error{
return err return err
} }
} }
func InArray(str string, list []string) bool{
for _, v := range list {
if v == str {
return true
}
}
return false
}
func Ignore(str string, list []string) bool{
for _, v := range list {
if strings.Contains(str, v) {
return true
}
}
return false
}