Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ package main
import (
"flag"
"fmt"
"github.com/pilu/fresh/runner"
"os"

"github.com/bom-d-van/fresh/runner"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion runner/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 8 additions & 2 deletions runner/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package runner

import (
"fmt"
"github.com/pilu/config"
"os"
"path/filepath"
"strconv"
"strings"
"time"

"github.com/pilu/config"
)

const (
Expand All @@ -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",
Expand Down Expand Up @@ -108,6 +110,10 @@ func root() string {
return settings["root"]
}

func extraDirs() string {
return settings["extra_dirs"]
}

func tmpPath() string {
return settings["tmp_path"]
}
Expand Down
70 changes: 40 additions & 30 deletions runner/watcher.go
Original file line number Diff line number Diff line change
@@ -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
})
}
}