#16 support for install and build

This commit is contained in:
asoseil 2017-10-15 22:21:29 +02:00
parent 43653ad810
commit 0a4b5eb1be
2 changed files with 15 additions and 8 deletions

10
cmd.go
View File

@ -33,6 +33,8 @@ type Cmds struct {
type Cmd struct { type Cmd struct {
Status bool `yaml:"status,omitempty" json:"status,omitempty"` Status bool `yaml:"status,omitempty" json:"status,omitempty"`
Args []string `yaml:"args,omitempty" json:"args,omitempty"` Args []string `yaml:"args,omitempty" json:"args,omitempty"`
Method []string `yaml:"method,omitempty" json:"method,omitempty"`
method []string
name, startTxt, endTxt string name, startTxt, endTxt string
} }
@ -151,14 +153,16 @@ func (r *realize) run(p *cli.Context) error {
// default settings // default settings
r.Schema[k].Cmds.Install = Cmd{ r.Schema[k].Cmds.Install = Cmd{
Status: elm.Cmds.Install.Status, Status: elm.Cmds.Install.Status,
Args: append([]string{"install"}, elm.Cmds.Install.Args...), Args: append([]string{}, elm.Cmds.Install.Args...),
method: []string{"go", "install"},
name: "Go Install", name: "Go Install",
startTxt: "Installing...", startTxt: "Installing...",
endTxt: "Installed", endTxt: "Installed",
} }
r.Schema[k].Cmds.Build = Cmd{ r.Schema[k].Cmds.Build = Cmd{
Status: elm.Cmds.Build.Status, Status: elm.Cmds.Build.Status,
Args: append([]string{"build"}, elm.Cmds.Build.Args...), Args: append([]string{}, elm.Cmds.Build.Args...),
method: []string{"go", "build"},
name: "Go Build", name: "Go Build",
startTxt: "Bulding...", startTxt: "Bulding...",
endTxt: "Built", endTxt: "Built",
@ -206,7 +210,7 @@ func (r *realize) remove(p *cli.Context) error {
return errors.New("no project found") return errors.New("no project found")
} }
// Insert a project if there isn't already one // Insert current project if there isn't already one
func (r *realize) insert(c *cli.Context) error { func (r *realize) insert(c *cli.Context) error {
if c.Bool("no-config") { if c.Bool("no-config") {
r.Schema = []Project{} r.Schema = []Project{}

View File

@ -21,12 +21,12 @@ var (
wg sync.WaitGroup wg sync.WaitGroup
) )
// Watcher struct defines the livereload's logic // Watch struct defines options for livereload
type Watch struct { type Watch struct {
Preview bool `yaml:"preview,omitempty" json:"preview,omitempty"`
Paths []string `yaml:"paths" json:"paths"` Paths []string `yaml:"paths" json:"paths"`
Exts []string `yaml:"extensions" json:"extensions"` Exts []string `yaml:"extensions" json:"extensions"`
Ignore []string `yaml:"ignored_paths,omitempty" json:"ignored_paths,omitempty"` Ignore []string `yaml:"ignored_paths,omitempty" json:"ignored_paths,omitempty"`
Preview bool `yaml:"preview,omitempty" json:"preview,omitempty"`
Scripts []Command `yaml:"scripts,omitempty" json:"scripts,omitempty"` Scripts []Command `yaml:"scripts,omitempty" json:"scripts,omitempty"`
} }
@ -83,7 +83,7 @@ type BufferOut struct {
Errors []string `json:"errors"` Errors []string `json:"errors"`
} }
// Watch the project by fsnotify // Watch the project
func (p *Project) watch() { func (p *Project) watch() {
p.watcher, _ = Watcher() p.watcher, _ = Watcher()
stop, exit := make(chan bool), make(chan os.Signal, 2) stop, exit := make(chan bool), make(chan os.Signal, 2)
@ -166,7 +166,7 @@ func (p *Project) err(err error) {
p.stamp("error", out, msg, "") p.stamp("error", out, msg, "")
} }
// Cmd calls an wrapper for execute the commands after/before // Cmd calls the method that execute commands after/before and display the results
func (p *Project) cmd(stop <-chan bool, flag string, global bool) { func (p *Project) cmd(stop <-chan bool, flag string, global bool) {
done := make(chan bool) done := make(chan bool)
// cmds are scheduled in sequence // cmds are scheduled in sequence
@ -214,7 +214,10 @@ func (p *Project) compile(stop <-chan bool, cmd Cmd) error {
channel := make(chan Result) channel := make(chan Result)
go func() { go func() {
log.Println(p.pname(p.Name, 1), ":", cmd.startTxt) log.Println(p.pname(p.Name, 1), ":", cmd.startTxt)
stream, err := p.goCompile(stop, cmd.Args) if len(cmd.Method) > 0 {
cmd.method = cmd.Method
}
stream, err := p.goCompile(stop, cmd.method, cmd.Args)
if stream != "killed" { if stream != "killed" {
channel <- Result{stream, err} channel <- Result{stream, err}
} }