custom path support

This commit is contained in:
alessio 2016-08-30 19:27:47 +02:00
parent 0fd83277d9
commit ef6f05d84c
3 changed files with 15 additions and 4 deletions

View File

@ -178,7 +178,7 @@ A Go build system with file watchers, output streams and live reload. Run, build
##### Milestone 1.1 ##### Milestone 1.1
- [ ] Testing on windows - [ ] Testing on windows
- [ ] Custom paths for the commands fast/add - [x] Custom paths for the commands fast/add
- [ ] Save output on a file - [ ] Save output on a file
- [ ] Enable the fields Before/After - [ ] Enable the fields Before/After
- [ ] Web panel - **Maybe** - [ ] Web panel - **Maybe**

View File

@ -3,6 +3,7 @@ package main
import ( import (
"fmt" "fmt"
r "github.com/tockins/realize/realize" r "github.com/tockins/realize/realize"
_ "github.com/tockins/realize/server"
"gopkg.in/urfave/cli.v2" "gopkg.in/urfave/cli.v2"
"log" "log"
"os" "os"
@ -61,6 +62,7 @@ func main() {
Name: "fast", Name: "fast",
Usage: "Build and watch file changes for a single project without any config file", Usage: "Build and watch file changes for a single project without any config file",
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{Name: "path", Aliases: []string{"b"}, Value: "", Usage: "Project base path"},
&cli.BoolFlag{Name: "build", Value: false, Usage: "Enables the build"}, &cli.BoolFlag{Name: "build", Value: false, Usage: "Enables the build"},
&cli.BoolFlag{Name: "no-run", Usage: "Disables the run"}, &cli.BoolFlag{Name: "no-run", Usage: "Disables the run"},
&cli.BoolFlag{Name: "no-bin", Usage: "Disables the installation"}, &cli.BoolFlag{Name: "no-bin", Usage: "Disables the installation"},

View File

@ -1,6 +1,7 @@
package realize package realize
import ( import (
"errors"
"fmt" "fmt"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"gopkg.in/urfave/cli.v2" "gopkg.in/urfave/cli.v2"
@ -78,7 +79,11 @@ func (p *Project) watching() {
} }
defer end() defer end()
p.walks(watcher) err = p.walks(watcher)
if err != nil {
fmt.Println(pname(p.Name, 1), ":", Red(err.Error()))
return
}
go routines(p, channel, &wr) go routines(p, channel, &wr)
p.reload = time.Now().Truncate(time.Second) p.reload = time.Now().Truncate(time.Second)
@ -189,7 +194,7 @@ func (p *Project) test(path string) error {
} }
// Walks the file tree of a project // Walks the file tree of a project
func (p *Project) walks(watcher *fsnotify.Watcher) { func (p *Project) walks(watcher *fsnotify.Watcher) error {
var files, folders int64 var files, folders int64
wd, _ := os.Getwd() wd, _ := os.Getwd()
@ -226,9 +231,12 @@ func (p *Project) walks(watcher *fsnotify.Watcher) {
if p.Path == "." || p.Path == "/" { if p.Path == "." || p.Path == "/" {
p.base = wd p.base = wd
p.Path = WorkingDir() p.Path = WorkingDir()
} else if filepath.IsAbs(p.Path) {
p.base = p.Path
} else { } else {
p.base = filepath.Join(wd, p.Path) p.base = filepath.Join(wd, p.Path)
} }
for _, dir := range p.Watcher.Paths { for _, dir := range p.Watcher.Paths {
base := filepath.Join(p.base, dir) base := filepath.Join(p.base, dir)
if _, err := os.Stat(base); err == nil { if _, err := os.Stat(base); err == nil {
@ -236,10 +244,11 @@ func (p *Project) walks(watcher *fsnotify.Watcher) {
log.Println(Red(err.Error())) log.Println(Red(err.Error()))
} }
} else { } else {
fmt.Println(pname(p.Name, 1), ":\t", Red(base+" path doesn't exist")) return errors.New(base + " path doesn't exist")
} }
} }
fmt.Println(Red("Watching: "), pname(p.Name, 1), Magenta(files), "file/s", Magenta(folders), "folder/s") fmt.Println(Red("Watching: "), pname(p.Name, 1), Magenta(files), "file/s", Magenta(folders), "folder/s")
return nil
} }
// Ignore validates a path // Ignore validates a path