lint
This commit is contained in:
parent
f78f432cd7
commit
f81fbecdea
|
@ -9,14 +9,14 @@ import (
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The Config model contain the general informations about a project
|
// Config struct contains the general informations about a project
|
||||||
type Config struct {
|
type Config struct {
|
||||||
file string
|
file string
|
||||||
Version string `yaml:"version,omitempty"`
|
Version string `yaml:"version,omitempty"`
|
||||||
Projects []Project
|
Projects []Project
|
||||||
}
|
}
|
||||||
|
|
||||||
// The New method puts the cli params in the struct
|
// New method puts the cli params in the struct
|
||||||
func New(params *cli.Context) *Config {
|
func New(params *cli.Context) *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
file: appFile,
|
file: appFile,
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// The Watcher struct defines the livereload's logic
|
||||||
type Watcher struct {
|
type Watcher struct {
|
||||||
// different before and after on re-run?
|
// different before and after on re-run?
|
||||||
Before []string `yaml:"before,omitempty"`
|
Before []string `yaml:"before,omitempty"`
|
||||||
|
@ -21,8 +22,10 @@ type Watcher struct {
|
||||||
Preview bool `yaml:"preview,omitempty"`
|
Preview bool `yaml:"preview,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Watch method adds the given paths on the Watcher
|
||||||
func (h *Config) Watch() error {
|
func (h *Config) Watch() error {
|
||||||
if err := h.Read(); err == nil {
|
err := h.Read();
|
||||||
|
if err == nil {
|
||||||
// loop projects
|
// loop projects
|
||||||
wg.Add(len(h.Projects))
|
wg.Add(len(h.Projects))
|
||||||
for k := range h.Projects {
|
for k := range h.Projects {
|
||||||
|
@ -31,11 +34,11 @@ func (h *Config) Watch() error {
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
return nil
|
return nil
|
||||||
} else {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Watching method is the main core. It manages the livereload and the watching
|
||||||
func (p *Project) Watching() {
|
func (p *Project) Watching() {
|
||||||
|
|
||||||
var wr sync.WaitGroup
|
var wr sync.WaitGroup
|
||||||
|
@ -128,34 +131,35 @@ func (p *Project) Watching() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Install call an implementation of the "go install"
|
||||||
func (p *Project) install() {
|
func (p *Project) install() {
|
||||||
if p.Bin {
|
if p.Bin {
|
||||||
LogSuccess(p.Name + ": Installing..")
|
LogSuccess(p.Name + ": Installing..")
|
||||||
if err := p.GoInstall(); err != nil {
|
if err := p.GoInstall(); err != nil {
|
||||||
Fail(err.Error())
|
Fail(err.Error())
|
||||||
return
|
|
||||||
} else {
|
} else {
|
||||||
LogSuccess(p.Name + ": Installed")
|
LogSuccess(p.Name + ": Installed")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build call an implementation of the "go build"
|
||||||
func (p *Project) build() {
|
func (p *Project) build() {
|
||||||
if p.Build {
|
if p.Build {
|
||||||
LogSuccess(p.Name + ": Building..")
|
LogSuccess(p.Name + ": Building..")
|
||||||
if err := p.GoBuild(); err != nil {
|
if err := p.GoBuild(); err != nil {
|
||||||
Fail(err.Error())
|
Fail(err.Error())
|
||||||
return
|
|
||||||
} else {
|
} else {
|
||||||
LogSuccess(p.Name + ": Builded")
|
LogSuccess(p.Name + ": Builded")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build call an implementation of the bin execution
|
||||||
func (p *Project) run(channel chan bool, wr *sync.WaitGroup) {
|
func (p *Project) run(channel chan bool, wr *sync.WaitGroup) {
|
||||||
if p.Run {
|
if p.Run {
|
||||||
if p.Bin {
|
if p.Bin {
|
||||||
|
@ -170,12 +174,13 @@ func (p *Project) run(channel chan bool, wr *sync.WaitGroup) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LogFail("Set 'app_run' to true for launch run")
|
LogFail("Set 'appRun' to true for launch run")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ignore validates a path
|
||||||
func (p *Project) ignore(str string) bool {
|
func (p *Project) ignore(str string) bool {
|
||||||
for _, v := range p.Watcher.Ignore {
|
for _, v := range p.Watcher.Ignore {
|
||||||
v = slash(v)
|
v = slash(v)
|
||||||
|
@ -186,6 +191,7 @@ func (p *Project) ignore(str string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if a string is inArray
|
||||||
func inArray(str string, list []string) bool {
|
func inArray(str string, list []string) bool {
|
||||||
for _, v := range list {
|
for _, v := range list {
|
||||||
if v == str {
|
if v == str {
|
||||||
|
@ -195,6 +201,7 @@ func inArray(str string, list []string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add a slash at the beginning if not exist
|
||||||
func slash(str string) string {
|
func slash(str string) string {
|
||||||
if string(str[0]) != "/" {
|
if string(str[0]) != "/" {
|
||||||
str = "/" + str
|
str = "/" + str
|
||||||
|
|
Loading…
Reference in New Issue