This commit is contained in:
asoseil 2017-11-27 00:01:08 +01:00
parent 19139c287b
commit 3f131e3817
6 changed files with 63 additions and 47 deletions

View File

@ -2,8 +2,8 @@ package realize
import ( import (
"fmt" "fmt"
"go/build"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"go/build"
"log" "log"
"os" "os"
"os/signal" "os/signal"
@ -14,17 +14,25 @@ import (
) )
const ( const (
// RPrefix tool name
RPrefix = "realize" RPrefix = "realize"
// RVersion current version
RVersion = "2.0" RVersion = "2.0"
// RExt file extension
RExt = ".yaml" RExt = ".yaml"
// RFile config file name
RFile = RPrefix + RExt RFile = RPrefix + RExt
// RDir config dir
RDir = "." + RPrefix RDir = "." + RPrefix
//RExtWin windows extension
RExtWin = ".exe" RExtWin = ".exe"
) )
type ( type (
// LogWriter used for all log
LogWriter struct{} LogWriter struct{}
// Realize main struct
Realize struct { Realize struct {
Settings Settings `yaml:"settings" json:"settings"` Settings Settings `yaml:"settings" json:"settings"`
Server Server `yaml:"server" json:"server"` Server Server `yaml:"server" json:"server"`
@ -38,6 +46,7 @@ type (
Reload Func `yaml:"-"` Reload Func `yaml:"-"`
} }
// Context is used as argument for func
Context struct { Context struct {
Path string Path string
Project *Project Project *Project
@ -46,6 +55,7 @@ type (
Event fsnotify.Event Event fsnotify.Event
} }
// Func is used instead realize func
Func func(Context) Func func(Context)
) )
@ -67,7 +77,7 @@ func (r *Realize) Stop() {
close(r.exit) close(r.exit)
} }
// Run realize workflow // Start realize workflow
func (r *Realize) Start() { func (r *Realize) Start() {
r.exit = make(chan os.Signal, 2) r.exit = make(chan os.Signal, 2)
signal.Notify(r.exit, os.Interrupt, syscall.SIGTERM) signal.Notify(r.exit, os.Interrupt, syscall.SIGTERM)

View File

@ -66,7 +66,7 @@ func PollingWatcher(interval time.Duration) FileWatcher {
} }
} }
// NewWatcher tries to use an fs-event watcher, and falls back to the poller if there is an error // NewFileWatcher tries to use an fs-event watcher, and falls back to the poller if there is an error
func NewFileWatcher(force bool, interval time.Duration) (FileWatcher, error) { func NewFileWatcher(force bool, interval time.Duration) (FileWatcher, error) {
if !force { if !force {
if w, err := EventWatcher(); err == nil { if w, err := EventWatcher(); err == nil {

View File

@ -127,7 +127,7 @@ func (p *Project) Before(){
p.stamp("log", out, msg, "") p.stamp("log", out, msg, "")
} }
// Error occurred // Err occurred
func (p *Project) Err(err error) { func (p *Project) Err(err error) {
if p.parent.Err != nil { if p.parent.Err != nil {
p.parent.Err(Context{Project: p}) p.parent.Err(Context{Project: p})

View File

@ -1,12 +1,12 @@
package realize package realize
import ( import (
"testing"
"log"
"bytes" "bytes"
"strings"
"os"
"errors" "errors"
"log"
"os"
"strings"
"testing"
) )
func TestProject_After(t *testing.T) { func TestProject_After(t *testing.T) {

View File

@ -5,11 +5,17 @@ import (
) )
var ( var (
//Output writer
Output = color.Output Output = color.Output
// Red color
Red = colorBase(color.FgHiRed) Red = colorBase(color.FgHiRed)
// Blue color
Blue = colorBase(color.FgHiBlue) Blue = colorBase(color.FgHiBlue)
// Green color
Green = colorBase(color.FgHiGreen) Green = colorBase(color.FgHiGreen)
// Yellow color
Yellow = colorBase(color.FgHiYellow) Yellow = colorBase(color.FgHiYellow)
// Magenta color
Magenta = colorBase(color.FgHiMagenta) Magenta = colorBase(color.FgHiMagenta)
) )

View File

@ -2,11 +2,11 @@ package main
import ( import (
"bytes" "bytes"
"errors"
"github.com/tockins/realize/realize" "github.com/tockins/realize/realize"
"log" "log"
"strings" "strings"
"testing" "testing"
"errors"
) )
var mockResponse interface{} var mockResponse interface{}