Merge pull request #49 from tockins/dev

Dev
This commit is contained in:
Alessio Pracchia 2017-04-15 20:17:36 +02:00 committed by GitHub
commit db7e339068
18 changed files with 510 additions and 554 deletions

View File

@ -1,8 +1,8 @@
language: go
go:
- 1.6
- 1.7
- 1.8
- tip
matrix:
allow_failures:

View File

@ -26,6 +26,15 @@ A Go build system with file watchers, output streams and live reload. Run, build
- Output streams and error logs (support for save on a file)
- Web Panel (projects list, config settings, logs)
v 1.4
- [ ] Watch dependencies options
- [ ] Input redirection (wait for an input and redirect)
- [ ] Web panel full support
- [ ] Multiple configurations
- [ ] GoMobile support ?
- [ ] Ignore path and files in gititnore ?
#### Wiki
- [Getting Started](#installation-and-usage)

View File

@ -64,7 +64,7 @@
{
"name": "github.com/tockins/interact",
"branch": "master",
"revision": "7dfb115b4849a7d87b2b8368a076959c2bf56e35",
"revision": "c424f9a549ee8ca6b36332a8cb4374701fff6ecb",
"packages": [
"."
]
@ -96,7 +96,7 @@
{
"name": "golang.org/x/crypto",
"branch": "master",
"revision": "3cb07270c9455e8ad27956a70891c962d121a228",
"revision": "cbc3d0884eac986df6e78a039b8792e869bff863",
"packages": [
"acme",
"acme/autocert"
@ -105,17 +105,15 @@
{
"name": "golang.org/x/net",
"branch": "master",
"revision": "ffcf1bedda3b04ebb15a168a59800a73d6dc0f4d",
"revision": "5602c733f70afc6dcec6766be0d5034d4c4f14de",
"packages": [
"context",
"context/ctxhttp",
"websocket"
]
},
{
"name": "golang.org/x/sys",
"branch": "master",
"revision": "9a7256cb28ed514b4e1e5f68959914c4c28a92e0",
"revision": "f3918c30c5c2cb527c0b071a27c35120a6c0719a",
"packages": [
"unix"
]
@ -131,7 +129,7 @@
{
"name": "gopkg.in/yaml.v2",
"branch": "v2",
"revision": "a3f3340b5840cee44f372bddb5880fcbc419b46a",
"revision": "cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b",
"packages": [
"."
]

File diff suppressed because it is too large Load Diff

View File

@ -2,21 +2,22 @@ package server
import (
"encoding/json"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
c "github.com/tockins/realize/settings"
w "github.com/tockins/realize/watcher"
"golang.org/x/net/websocket"
"gopkg.in/urfave/cli.v2"
"net/http"
"strconv"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/tockins/realize/settings"
"github.com/tockins/realize/watcher"
"golang.org/x/net/websocket"
"gopkg.in/urfave/cli.v2"
)
// Server settings
type Server struct {
*c.Settings `yaml:"-"`
*w.Blueprint `yaml:"-"`
Sync chan string `yaml:"-"`
*settings.Settings `yaml:"-"`
*watcher.Blueprint `yaml:"-"`
Sync chan string `yaml:"-"`
}
// Render return a web pages defined in bindata

View File

@ -2,7 +2,7 @@ package server
import (
"bytes"
"errors"
"fmt"
"io"
"os/exec"
"runtime"
@ -22,9 +22,10 @@ func init() {
// Open a url in the default browser
func Open(url string) (io.Writer, error) {
open, err := cmd[runtime.GOOS]
goos := runtime.GOOS
open, err := cmd[goos]
if !err {
return nil, errors.New("This operating system is not supported.")
return nil, fmt.Errorf("operating system %q is not supported", goos)
}
cmd := exec.Command(open, url)
cmd.Stderr = &stderr

View File

@ -1,89 +0,0 @@
package settings
import (
"github.com/fatih/color"
)
// Colors allowed
type Colors struct {
Red
Blue
Yellow
Magenta
Green
}
// Red color
type Red struct{}
// Blue color
type Blue struct{}
// Yellow color
type Yellow struct{}
// Magenta color
type Magenta struct{}
// Green color
type Green struct{}
// Regular font in red
func (c Red) Regular(t ...interface{}) string {
r := color.New(color.FgRed).SprintFunc()
return r(t...)
}
// Bold font in red
func (c Red) Bold(t ...interface{}) string {
r := color.New(color.FgRed, color.Bold).SprintFunc()
return r(t...)
}
// Regular font in blue
func (c Blue) Regular(t ...interface{}) string {
r := color.New(color.FgBlue).SprintFunc()
return r(t...)
}
// Bold font in blue
func (c Blue) Bold(t ...interface{}) string {
r := color.New(color.FgBlue, color.Bold).SprintFunc()
return r(t...)
}
// Regular font in yellow
func (c Yellow) Regular(t ...interface{}) string {
r := color.New(color.FgYellow).SprintFunc()
return r(t...)
}
// Bold font in red
func (c Yellow) Bold(t ...interface{}) string {
r := color.New(color.FgYellow, color.Bold).SprintFunc()
return r(t...)
}
// Regular font in magenta
func (c Magenta) Regular(t ...interface{}) string {
r := color.New(color.FgMagenta).SprintFunc()
return r(t...)
}
// Bold font in magenta
func (c Magenta) Bold(t ...interface{}) string {
r := color.New(color.FgMagenta, color.Bold).SprintFunc()
return r(t...)
}
// Regular font in green
func (c Green) Regular(t ...interface{}) string {
r := color.New(color.FgGreen).SprintFunc()
return r(t...)
}
// Bold font in red
func (c Green) Bold(t ...interface{}) string {
r := color.New(color.FgGreen, color.Bold).SprintFunc()
return r(t...)
}

View File

@ -5,12 +5,13 @@ package settings
import "syscall"
// Flimit defines the max number of watched files
func (s *Settings) Flimit() {
func (s *Settings) Flimit() error {
var rLimit syscall.Rlimit
rLimit.Max = uint64(s.Config.Flimit)
rLimit.Cur = uint64(s.Config.Flimit)
err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
s.Fatal(err, "Error setting rlimit")
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil {
return err
}
return nil
}

View File

@ -1,6 +1,7 @@
// build windows
package settings
// Flimit defines the max number of watched files
func (s *Settings) Flimit() {
return
func (s *Settings) Flimit() error {
return nil
}

View File

@ -9,12 +9,12 @@ import (
// Stream return a byte stream of a given file
func (s Settings) Stream(file string) ([]byte, error) {
_, err := os.Stat(file)
if err == nil {
content, err := ioutil.ReadFile(file)
s.Validate(err)
return content, err
if err != nil {
return nil, err
}
return nil, err
content, err := ioutil.ReadFile(file)
s.Validate(err)
return content, err
}
// Write a file given a name and a byte stream

View File

@ -1,14 +1,14 @@
package settings
import (
"gopkg.in/yaml.v2"
"os"
"time"
yaml "gopkg.in/yaml.v2"
)
// Settings defines a group of general settings
type Settings struct {
Colors `yaml:"-"`
Config `yaml:",inline" json:"config"`
Resources `yaml:"resources" json:"resources"`
Server `yaml:"server,omitempty" json:"server,omitempty"`
@ -54,7 +54,7 @@ func (s *Settings) Read(out interface{}) error {
err = yaml.Unmarshal(content, out)
return err
}
return err
return nil
}
// Record create and unmarshal the yaml config file

View File

@ -5,6 +5,8 @@ import (
"os"
"path/filepath"
"strings"
"github.com/tockins/realize/style"
)
// Wdir return the current working directory
@ -25,7 +27,7 @@ func (s Settings) Validate(err error) error {
// Fatal prints a fatal error with its additional messages
func (s Settings) Fatal(err error, msg ...interface{}) {
if len(msg) > 0 && err != nil {
log.Fatalln(s.Red.Regular(msg...), err.Error())
log.Fatalln(style.Red.Regular(msg...), err.Error())
} else if err != nil {
log.Fatalln(err.Error())
}

24
style/style.go Normal file
View File

@ -0,0 +1,24 @@
package style
import (
"github.com/fatih/color"
)
type colorBase color.Attribute
func (s colorBase) Regular(a ...interface{}) string {
return color.New(color.Attribute(s)).Sprint(a...)
}
func (s colorBase) Bold(a ...interface{}) string {
return color.New(color.Attribute(s), color.Bold).Sprint(a...)
}
// allowed colors
var (
Red = colorBase(color.FgRed)
Blue = colorBase(color.FgBlue)
Yellow = colorBase(color.FgYellow)
Magenta = colorBase(color.FgMagenta)
Green = colorBase(color.FgGreen)
)

View File

@ -1,10 +1,12 @@
package cli
package watcher
import (
"errors"
"fmt"
"gopkg.in/urfave/cli.v2"
"strings"
"github.com/tockins/realize/style"
cli "gopkg.in/urfave/cli.v2"
)
// Run launches the toolchain for each project
@ -80,7 +82,7 @@ func (h *Blueprint) Remove(p *cli.Context) error {
return nil
}
}
return errors.New("No project found.")
return errors.New("no project found")
}
// List of all the projects
@ -88,49 +90,49 @@ func (h *Blueprint) List() error {
err := h.check()
if err == nil {
for _, val := range h.Projects {
fmt.Println(h.Blue.Bold("[") + strings.ToUpper(val.Name) + h.Blue.Bold("]"))
name := h.Magenta.Bold("[") + strings.ToUpper(val.Name) + h.Magenta.Bold("]")
fmt.Println(style.Blue.Bold("[") + strings.ToUpper(val.Name) + style.Blue.Bold("]"))
name := style.Magenta.Bold("[") + strings.ToUpper(val.Name) + style.Magenta.Bold("]")
fmt.Println(name, h.Yellow.Regular("Base Path"), ":", h.Magenta.Regular(val.Path))
fmt.Println(name, h.Yellow.Regular("Fmt"), ":", h.Magenta.Regular(val.Fmt))
fmt.Println(name, h.Yellow.Regular("Generate"), ":", h.Magenta.Regular(val.Generate))
fmt.Println(name, h.Yellow.Regular("Test"), ":", h.Magenta.Regular(val.Test))
fmt.Println(name, h.Yellow.Regular("Install"), ":", h.Magenta.Regular(val.Bin))
fmt.Println(name, h.Yellow.Regular("Build"), ":", h.Magenta.Regular(val.Build))
fmt.Println(name, h.Yellow.Regular("Run"), ":", h.Magenta.Regular(val.Run))
fmt.Println(name, style.Yellow.Regular("Base Path"), ":", style.Magenta.Regular(val.Path))
fmt.Println(name, style.Yellow.Regular("Fmt"), ":", style.Magenta.Regular(val.Fmt))
fmt.Println(name, style.Yellow.Regular("Generate"), ":", style.Magenta.Regular(val.Generate))
fmt.Println(name, style.Yellow.Regular("Test"), ":", style.Magenta.Regular(val.Test))
fmt.Println(name, style.Yellow.Regular("Install"), ":", style.Magenta.Regular(val.Bin))
fmt.Println(name, style.Yellow.Regular("Build"), ":", style.Magenta.Regular(val.Build))
fmt.Println(name, style.Yellow.Regular("Run"), ":", style.Magenta.Regular(val.Run))
if len(val.Params) > 0 {
fmt.Println(name, h.Yellow.Regular("Params"), ":", h.Magenta.Regular(val.Params))
fmt.Println(name, style.Yellow.Regular("Params"), ":", style.Magenta.Regular(val.Params))
}
fmt.Println(name, h.Yellow.Regular("Watcher"), ":")
fmt.Println(name, "\t", h.Yellow.Regular("Preview"), ":", h.Magenta.Regular(val.Watcher.Preview))
fmt.Println(name, style.Yellow.Regular("Watcher"), ":")
fmt.Println(name, "\t", style.Yellow.Regular("Preview"), ":", style.Magenta.Regular(val.Watcher.Preview))
if len(val.Watcher.Exts) > 0 {
fmt.Println(name, "\t", h.Yellow.Regular("Extensions"), ":", h.Magenta.Regular(val.Watcher.Exts))
fmt.Println(name, "\t", style.Yellow.Regular("Extensions"), ":", style.Magenta.Regular(val.Watcher.Exts))
}
if len(val.Watcher.Paths) > 0 {
fmt.Println(name, "\t", h.Yellow.Regular("Paths"), ":", h.Magenta.Regular(val.Watcher.Paths))
fmt.Println(name, "\t", style.Yellow.Regular("Paths"), ":", style.Magenta.Regular(val.Watcher.Paths))
}
if len(val.Watcher.Ignore) > 0 {
fmt.Println(name, "\t", h.Yellow.Regular("Ignored paths"), ":", h.Magenta.Regular(val.Watcher.Ignore))
fmt.Println(name, "\t", style.Yellow.Regular("Ignored paths"), ":", style.Magenta.Regular(val.Watcher.Ignore))
}
if len(val.Watcher.Scripts) > 0 {
fmt.Println(name, "\t", h.Yellow.Regular("Scripts"), ":")
fmt.Println(name, "\t", style.Yellow.Regular("Scripts"), ":")
for _, v := range val.Watcher.Scripts {
if v.Command != "" {
fmt.Println(name, "\t\t", h.Magenta.Regular("-"), h.Yellow.Regular("Command"), ":", h.Magenta.Regular(v.Command))
fmt.Println(name, "\t\t", style.Magenta.Regular("-"), style.Yellow.Regular("Command"), ":", style.Magenta.Regular(v.Command))
if v.Path != "" {
fmt.Println(name, "\t\t", h.Yellow.Regular("Path"), ":", h.Magenta.Regular(v.Path))
fmt.Println(name, "\t\t", style.Yellow.Regular("Path"), ":", style.Magenta.Regular(v.Path))
}
if v.Type != "" {
fmt.Println(name, "\t\t", h.Yellow.Regular("Type"), ":", h.Magenta.Regular(v.Type))
fmt.Println(name, "\t\t", style.Yellow.Regular("Type"), ":", style.Magenta.Regular(v.Type))
}
}
}
}
fmt.Println(name, h.Yellow.Regular("Streams"), ":")
fmt.Println(name, "\t", h.Yellow.Regular("Cli Out"), ":", h.Magenta.Regular(val.Streams.CliOut))
fmt.Println(name, "\t", h.Yellow.Regular("File Out"), ":", h.Magenta.Regular(val.Streams.FileOut))
fmt.Println(name, "\t", h.Yellow.Regular("File Log"), ":", h.Magenta.Regular(val.Streams.FileLog))
fmt.Println(name, "\t", h.Yellow.Regular("File Err"), ":", h.Magenta.Regular(val.Streams.FileErr))
fmt.Println(name, style.Yellow.Regular("Streams"), ":")
fmt.Println(name, "\t", style.Yellow.Regular("Cli Out"), ":", style.Magenta.Regular(val.Streams.CliOut))
fmt.Println(name, "\t", style.Yellow.Regular("File Out"), ":", style.Magenta.Regular(val.Streams.FileOut))
fmt.Println(name, "\t", style.Yellow.Regular("File Log"), ":", style.Magenta.Regular(val.Streams.FileLog))
fmt.Println(name, "\t", style.Yellow.Regular("File Err"), ":", style.Magenta.Regular(val.Streams.FileErr))
}
return nil
}
@ -143,5 +145,5 @@ func (h *Blueprint) check() error {
h.Clean()
return nil
}
return errors.New("There are no projects. The config file is empty.")
return errors.New("there are no projects")
}

View File

@ -1,4 +1,4 @@
package cli
package watcher
import (
"bufio"
@ -11,6 +11,8 @@ import (
"strings"
"sync"
"time"
"github.com/tockins/realize/style"
)
// GoRun is an implementation of the bin execution
@ -46,7 +48,7 @@ func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Failed to stop: " + err.Error()})
p.Fatal(err, "Failed to stop", ":")
}
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Regular("Ended"))
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", style.Red.Regular("Ended"))
out := BufferOut{Time: time.Now(), Text: "Ended", Type: "Go Run"}
p.print("log", out, msg, "")
wr.Done()
@ -55,11 +57,11 @@ func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
stdout, err := build.StdoutPipe()
stderr, err := build.StderrPipe()
if err != nil {
log.Println(p.Red.Bold(err.Error()))
log.Println(style.Red.Bold(err.Error()))
return err
}
if err := build.Start(); err != nil {
log.Println(p.Red.Bold(err.Error()))
log.Println(style.Red.Bold(err.Error()))
return err
}
close(runner)
@ -70,7 +72,7 @@ func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
for output.Scan() {
select {
default:
msg := fmt.Sprintln(p.pname(p.Name, 3), ":", p.Blue.Regular(output.Text()))
msg := fmt.Sprintln(p.pname(p.Name, 3), ":", style.Blue.Regular(output.Text()))
if isError {
out := BufferOut{Time: time.Now(), Text: output.Text(), Type: "Go Run"}
p.print("error", out, msg, "")

View File

@ -1,10 +1,11 @@
package cli
package watcher
import (
c "github.com/tockins/realize/settings"
"log"
"sync"
"time"
"github.com/tockins/realize/settings"
)
var wg sync.WaitGroup
@ -21,35 +22,34 @@ type pollWatcher struct {
// Log struct
type logWriter struct {
c.Colors
}
// Blueprint struct contains a projects list
type Blueprint struct {
*c.Settings `yaml:"-"`
Projects []Project `yaml:"projects,omitempty" json:"projects,omitempty"`
Sync chan string `yaml:"-"`
*settings.Settings `yaml:"-"`
Projects []Project `yaml:"projects,omitempty" json:"projects,omitempty"`
Sync chan string `yaml:"-"`
}
// Project defines the informations of a single project
type Project struct {
c.Settings `yaml:"-"`
LastChangedOn time.Time `yaml:"-" json:"-"`
base string
Name string `yaml:"name" json:"name"`
Path string `yaml:"path" json:"path"`
Fmt bool `yaml:"fmt" json:"fmt"`
Generate bool `yaml:"generate" json:"generate"`
Test bool `yaml:"test" json:"test"`
Bin bool `yaml:"bin" json:"bin"`
Build bool `yaml:"build" json:"build"`
Run bool `yaml:"run" json:"run"`
Params []string `yaml:"params,omitempty" json:"params,omitempty"`
Watcher Watcher `yaml:"watcher" json:"watcher"`
Streams Streams `yaml:"streams" json:"streams"`
Buffer Buffer `yaml:"-" json:"buffer"`
parent *Blueprint
path string
settings.Settings `yaml:"-"`
LastChangedOn time.Time `yaml:"-" json:"-"`
base string
Name string `yaml:"name" json:"name"`
Path string `yaml:"path" json:"path"`
Fmt bool `yaml:"fmt" json:"fmt"`
Generate bool `yaml:"generate" json:"generate"`
Test bool `yaml:"test" json:"test"`
Bin bool `yaml:"bin" json:"bin"`
Build bool `yaml:"build" json:"build"`
Run bool `yaml:"run" json:"run"`
Params []string `yaml:"params,omitempty" json:"params,omitempty"`
Watcher Watcher `yaml:"watcher" json:"watcher"`
Streams Streams `yaml:"streams" json:"streams"`
Buffer Buffer `yaml:"-" json:"buffer"`
parent *Blueprint
path string
}
// Watcher struct defines the livereload's logic

View File

@ -1,10 +1,12 @@
package cli
package watcher
import (
"errors"
"fmt"
"gopkg.in/urfave/cli.v2"
"time"
"github.com/tockins/realize/style"
cli "gopkg.in/urfave/cli.v2"
)
// Argsparam parse one by one the given argumentes
@ -42,5 +44,5 @@ func inArray(str string, list []string) bool {
// Rewrite the layout of the log timestamp
func (w logWriter) Write(bytes []byte) (int, error) {
return fmt.Print(w.Yellow.Regular("[") + time.Now().Format("15:04:05") + w.Yellow.Regular("]") + string(bytes))
return fmt.Print(style.Yellow.Regular("[") + time.Now().Format("15:04:05") + style.Yellow.Regular("]") + string(bytes))
}

View File

@ -1,9 +1,8 @@
package cli
package watcher
import (
"errors"
"fmt"
"github.com/fsnotify/fsnotify"
"log"
"math/big"
"os"
@ -14,6 +13,9 @@ import (
"sync"
"syscall"
"time"
"github.com/fsnotify/fsnotify"
"github.com/tockins/realize/style"
)
var msg string
@ -71,7 +73,7 @@ func (p *Project) watchByPolling() {
}
p.LastChangedOn = time.Now().Truncate(time.Second)
// repeat the initial cycle
msg = fmt.Sprintln(p.pname(p.Name, 4), ":", p.Magenta.Bold(strings.ToUpper(ext[1:])+" changed"), p.Magenta.Bold(file))
msg = fmt.Sprintln(p.pname(p.Name, 4), ":", style.Magenta.Bold(strings.ToUpper(ext[1:])+" changed"), style.Magenta.Bold(file))
out = BufferOut{Time: time.Now(), Text: strings.ToUpper(ext[1:]) + " changed " + file}
p.print("log", out, msg, "")
@ -88,7 +90,7 @@ func (p *Project) watchByPolling() {
base := filepath.Join(p.base, dir)
if _, err := os.Stat(base); err == nil {
if err := filepath.Walk(base, walk); err != nil {
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Regular(err.Error()))
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", style.Red.Regular(err.Error()))
out = BufferOut{Time: time.Now(), Text: err.Error()}
p.print("error", out, msg, "")
}
@ -147,7 +149,7 @@ func (p *Project) watchByNotify() {
}
p.LastChangedOn = time.Now().Truncate(time.Second)
// repeat the initial cycle
msg = fmt.Sprintln(p.pname(p.Name, 4), ":", p.Magenta.Bold(strings.ToUpper(ext[1:])+" changed"), p.Magenta.Bold(file))
msg = fmt.Sprintln(p.pname(p.Name, 4), ":", style.Magenta.Bold(strings.ToUpper(ext[1:])+" changed"), style.Magenta.Bold(file))
out = BufferOut{Time: time.Now(), Text: strings.ToUpper(ext[1:]) + " changed " + file}
p.print("log", out, msg, "")
@ -160,7 +162,7 @@ func (p *Project) watchByNotify() {
}
}
case err := <-watcher.Errors:
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Regular(err.Error()))
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", style.Red.Regular(err.Error()))
out = BufferOut{Time: time.Now(), Text: err.Error()}
p.print("error", out, msg, "")
case <-exit:
@ -206,13 +208,13 @@ func (p *Project) watch(watcher watcher) error {
base := filepath.Join(p.base, dir)
if _, err := os.Stat(base); err == nil {
if err := filepath.Walk(base, walk); err != nil {
log.Println(p.Red.Bold(err.Error()))
log.Println(style.Red.Bold(err.Error()))
}
} else {
return errors.New(base + " path doesn't exist")
}
}
msg = fmt.Sprintln(p.pname(p.Name, 1), ":", p.Blue.Bold("Watching"), p.Magenta.Bold(files), "file/s", p.Magenta.Bold(folders), "folder/s")
msg = fmt.Sprintln(p.pname(p.Name, 1), ":", style.Blue.Bold("Watching"), style.Magenta.Bold(files), "file/s", style.Magenta.Bold(folders), "folder/s")
out = BufferOut{Time: time.Now(), Text: "Watching " + strconv.FormatInt(files, 10) + " files/s " + strconv.FormatInt(folders, 10) + " folder/s"}
p.print("log", out, msg, "")
return nil
@ -225,11 +227,11 @@ func (p *Project) install() error {
log.Println(p.pname(p.Name, 1), ":", "Installing..")
stream, err := p.goInstall()
if err != nil {
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Install"), p.Red.Regular(err.Error()))
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", style.Red.Bold("Go Install"), style.Red.Regular(err.Error()))
out = BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Install", Stream: stream}
p.print("error", out, msg, stream)
} else {
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", p.Green.Regular("Installed")+" after", p.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", style.Green.Regular("Installed")+" after", style.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
out = BufferOut{Time: time.Now(), Text: "Installed after " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"}
p.print("log", out, msg, stream)
}
@ -248,7 +250,7 @@ func (p *Project) run(channel chan bool, wr *sync.WaitGroup) {
for {
select {
case <-runner:
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", p.Green.Regular("Has been run")+" after", p.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", style.Green.Regular("Has been run")+" after", style.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
out = BufferOut{Time: time.Now(), Text: "Has been run after " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"}
p.print("log", out, msg, "")
return
@ -264,11 +266,11 @@ func (p *Project) build() error {
log.Println(p.pname(p.Name, 1), ":", "Building..")
stream, err := p.goBuild()
if err != nil {
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Build"), p.Red.Regular(err.Error()))
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", style.Red.Bold("Go Build"), style.Red.Regular(err.Error()))
out = BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Build", Stream: stream}
p.print("error", out, msg, stream)
} else {
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", p.Green.Regular("Builded")+" after", p.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", style.Green.Regular("Builded")+" after", style.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
out = BufferOut{Time: time.Now(), Text: "Builded after " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"}
p.print("log", out, msg, stream)
}
@ -281,7 +283,7 @@ func (p *Project) build() error {
func (p *Project) fmt(path string) error {
if p.Fmt && strings.HasSuffix(path, ".go") {
if stream, err := p.goTools(p.base, "gofmt", "-s", "-w", "-e", path); err != nil {
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Fmt"), p.Red.Regular("there are some errors in"), ":", p.Magenta.Bold(path))
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", style.Red.Bold("Go Fmt"), style.Red.Regular("there are some errors in"), ":", style.Magenta.Bold(path))
out = BufferOut{Time: time.Now(), Text: "there are some errors in", Path: path, Type: "Go Fmt", Stream: stream}
p.print("error", out, msg, stream)
return err
@ -294,7 +296,7 @@ func (p *Project) fmt(path string) error {
func (p *Project) generate(path string) error {
if p.Generate {
if stream, err := p.goTools(path, "go", "generate"); err != nil {
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Generate"), p.Red.Regular("there are some errors in"), ":", p.Magenta.Bold(path))
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", style.Red.Bold("Go Generate"), style.Red.Regular("there are some errors in"), ":", style.Magenta.Bold(path))
out = BufferOut{Time: time.Now(), Text: "there are some errors in", Path: path, Type: "Go Generate", Stream: stream}
p.print("error", out, msg, stream)
return err
@ -307,7 +309,7 @@ func (p *Project) generate(path string) error {
func (p *Project) test(path string) error {
if p.Test {
if stream, err := p.goTools(path, "go", "test"); err != nil {
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Test"), p.Red.Regular("there are some errors in "), ":", p.Magenta.Bold(path))
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", style.Red.Bold("Go Test"), style.Red.Regular("there are some errors in "), ":", style.Magenta.Bold(path))
out = BufferOut{Time: time.Now(), Text: "there are some errors in", Path: path, Type: "Go Test", Stream: stream}
p.print("error", out, msg, stream)
return err
@ -321,7 +323,7 @@ func (p *Project) cmd(flag string) {
for _, cmd := range p.Watcher.Scripts {
if strings.ToLower(cmd.Type) == flag {
errors, logs := p.command(cmd)
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", p.Green.Bold("Command"), p.Green.Bold("\"")+cmd.Command+p.Green.Bold("\""))
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", style.Green.Bold("Command"), style.Green.Bold("\"")+cmd.Command+style.Green.Bold("\""))
out = BufferOut{Time: time.Now(), Text: cmd.Command, Type: flag}
if logs != "" {
p.print("log", out, msg, "")
@ -335,7 +337,7 @@ func (p *Project) cmd(flag string) {
p.print("log", out, "", msg)
}
if errors != "" {
msg = fmt.Sprintln(p.Red.Regular(errors))
msg = fmt.Sprintln(style.Red.Regular(errors))
out = BufferOut{Time: time.Now(), Text: errors, Type: flag}
p.print("error", out, "", msg)
}
@ -368,19 +370,19 @@ func (p *Project) routines(channel chan bool, wr *sync.WaitGroup) {
func (p *Project) pname(name string, color int) string {
switch color {
case 1:
name = p.Yellow.Regular("[") + strings.ToUpper(name) + p.Yellow.Regular("]")
name = style.Yellow.Regular("[") + strings.ToUpper(name) + style.Yellow.Regular("]")
break
case 2:
name = p.Yellow.Regular("[") + p.Red.Bold(strings.ToUpper(name)) + p.Yellow.Regular("]")
name = style.Yellow.Regular("[") + style.Red.Bold(strings.ToUpper(name)) + style.Yellow.Regular("]")
break
case 3:
name = p.Yellow.Regular("[") + p.Blue.Bold(strings.ToUpper(name)) + p.Yellow.Regular("]")
name = style.Yellow.Regular("[") + style.Blue.Bold(strings.ToUpper(name)) + style.Yellow.Regular("]")
break
case 4:
name = p.Yellow.Regular("[") + p.Magenta.Bold(strings.ToUpper(name)) + p.Yellow.Regular("]")
name = style.Yellow.Regular("[") + style.Magenta.Bold(strings.ToUpper(name)) + style.Yellow.Regular("]")
break
case 5:
name = p.Yellow.Regular("[") + p.Green.Bold(strings.ToUpper(name)) + p.Yellow.Regular("]")
name = style.Yellow.Regular("[") + style.Green.Bold(strings.ToUpper(name)) + style.Yellow.Regular("]")
break
}
return name