From 686d81e4e173bebc47d5d418dce7a5ba5892324d Mon Sep 17 00:00:00 2001 From: bom_d_van Date: Wed, 21 Jan 2015 16:48:47 +0800 Subject: [PATCH 1/6] can watch extra dirs --- runner/settings.go | 8 +++++++- runner/watcher.go | 30 +++++++++++++++++++----------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/runner/settings.go b/runner/settings.go index 61e2412..e149232 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,6 +19,7 @@ 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", @@ -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..f885eeb 100644 --- a/runner/watcher.go +++ b/runner/watcher.go @@ -1,10 +1,11 @@ package runner import ( - "github.com/howeyc/fsnotify" "os" "path/filepath" "strings" + + "github.com/howeyc/fsnotify" ) func watchFolder(path string) { @@ -36,16 +37,23 @@ func watchFolder(path string) { } 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 + }) + } } From 9da3e6f8623741a34da0b3bb91c2796c4e2f10bd Mon Sep 17 00:00:00 2001 From: bom_d_van Date: Wed, 25 Mar 2015 14:36:15 +0800 Subject: [PATCH 2/6] get rid of pilu dependence --- main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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() { From 568a94f0a06519d4356139426a3619ff2e2ad92d Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 10 Nov 2015 16:40:52 +0800 Subject: [PATCH 3/6] build with enterprise tags --- runner/build.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 { From 9ea4bb54c74e7814ef60153c83342bab8a4cec70 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 10 Nov 2015 16:41:16 +0800 Subject: [PATCH 4/6] Ignore node modules, public/system, templates files --- runner/settings.go | 4 ++-- runner/watcher.go | 40 +++++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/runner/settings.go b/runner/settings.go index e149232..90c0095 100644 --- a/runner/settings.go +++ b/runner/settings.go @@ -19,11 +19,11 @@ const ( var settings = map[string]string{ "config_path": "./runner.conf", "root": ".", - "extra_dirs": "", + "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", diff --git a/runner/watcher.go b/runner/watcher.go index f885eeb..a7c0787 100644 --- a/runner/watcher.go +++ b/runner/watcher.go @@ -9,30 +9,32 @@ import ( ) func watchFolder(path string) { - watcher, err := fsnotify.NewWatcher() - if err != nil { - fatal(err) - } + if !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) + } } } From c6ee934a1677b9d39ff08e98ec01c2bf269fe75d Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Thu, 4 Aug 2016 13:58:34 +0800 Subject: [PATCH 5/6] ignore vendor --- runner/watcher.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/watcher.go b/runner/watcher.go index a7c0787..036b202 100644 --- a/runner/watcher.go +++ b/runner/watcher.go @@ -9,7 +9,7 @@ import ( ) func watchFolder(path string) { - if !strings.Contains(path, "/node_modules") && !strings.Contains(path, "public/system/") && !strings.Contains(path, ".tmpl") { + if !strings.Contains(path, "vendor/") && !strings.Contains(path, "node_modules") && !strings.Contains(path, "public/system/") && !strings.Contains(path, ".tmpl") { watcher, err := fsnotify.NewWatcher() if err != nil { fatal(err) From 22fbf20bbc0e119f5aa1ee1c320b344b4fad52f3 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Thu, 4 Aug 2016 14:21:55 +0800 Subject: [PATCH 6/6] Ignore bower_components --- runner/watcher.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/watcher.go b/runner/watcher.go index 036b202..544302d 100644 --- a/runner/watcher.go +++ b/runner/watcher.go @@ -9,7 +9,7 @@ import ( ) func watchFolder(path string) { - if !strings.Contains(path, "vendor/") && !strings.Contains(path, "node_modules") && !strings.Contains(path, "public/system/") && !strings.Contains(path, ".tmpl") { + 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)