diff --git a/main.go b/main.go index 1dea9dd..d046965 100644 --- a/main.go +++ b/main.go @@ -15,8 +15,9 @@ package main import ( "flag" "fmt" - "github.com/pilu/fresh/runner" "os" + + "github.com/bom-d-van/fresh/runner" ) func main() { diff --git a/runner/build.go b/runner/build.go index 7f0242f..a80135b 100644 --- a/runner/build.go +++ b/runner/build.go @@ -10,7 +10,7 @@ import ( func build() (string, bool) { buildLog("Building...") - cmd := exec.Command("go", "build", "-o", buildPath(), root()) + cmd := exec.Command("go", "build", "-tags", "enterprise", "-o", buildPath(), root()) stderr, err := cmd.StderrPipe() if err != nil { diff --git a/runner/settings.go b/runner/settings.go index 61e2412..90c0095 100644 --- a/runner/settings.go +++ b/runner/settings.go @@ -2,12 +2,13 @@ package runner import ( "fmt" - "github.com/pilu/config" "os" "path/filepath" "strconv" "strings" "time" + + "github.com/pilu/config" ) const ( @@ -18,10 +19,11 @@ const ( var settings = map[string]string{ "config_path": "./runner.conf", "root": ".", + "extra_dirs": "", "tmp_path": "./tmp", "build_name": "runner-build", "build_log": "runner-build-errors.log", - "valid_ext": ".go, .tpl, .tmpl, .html", + "valid_ext": ".go", "build_delay": "600", "colors": "1", "log_color_main": "cyan", @@ -108,6 +110,10 @@ func root() string { return settings["root"] } +func extraDirs() string { + return settings["extra_dirs"] +} + func tmpPath() string { return settings["tmp_path"] } diff --git a/runner/watcher.go b/runner/watcher.go index 7df2706..544302d 100644 --- a/runner/watcher.go +++ b/runner/watcher.go @@ -1,51 +1,61 @@ package runner import ( - "github.com/howeyc/fsnotify" "os" "path/filepath" "strings" + + "github.com/howeyc/fsnotify" ) func watchFolder(path string) { - watcher, err := fsnotify.NewWatcher() - if err != nil { - fatal(err) - } + if !strings.Contains(path, "vendor/") && !strings.Contains(path, "bower_components") && !strings.Contains(path, "node_modules") && !strings.Contains(path, "public/system/") && !strings.Contains(path, ".tmpl") { + watcher, err := fsnotify.NewWatcher() + if err != nil { + fatal(err) + } - go func() { - for { - select { - case ev := <-watcher.Event: - if isWatchedFile(ev.Name) { - watcherLog("sending event %s", ev) - startChannel <- ev.String() + go func() { + for { + select { + case ev := <-watcher.Event: + if isWatchedFile(ev.Name) { + watcherLog("sending event %s", ev) + startChannel <- ev.String() + } + case err := <-watcher.Error: + watcherLog("error: %s", err) } - case err := <-watcher.Error: - watcherLog("error: %s", err) } - } - }() + }() - watcherLog("Watching %s", path) - err = watcher.Watch(path) + watcherLog("Watching %s", path) + err = watcher.Watch(path) - if err != nil { - fatal(err) + if err != nil { + fatal(err) + } } } func watch() { - root := root() - filepath.Walk(root, func(path string, info os.FileInfo, err error) error { - if info.IsDir() && !isTmpDir(path) { - if len(path) > 1 && strings.HasPrefix(filepath.Base(path), ".") { - return filepath.SkipDir - } + // root := root() + paths := root() + if extraDirs := extraDirs(); extraDirs != "" { + paths += "," + extraDirs + } - watchFolder(path) - } + for _, root := range strings.Split(paths, ",") { + filepath.Walk(root, func(path string, info os.FileInfo, err error) error { + if info.IsDir() && !isTmpDir(path) { + if len(path) > 1 && strings.HasPrefix(filepath.Base(path), ".") { + return filepath.SkipDir + } - return err - }) + watchFolder(path) + } + + return err + }) + } }