realize/realize/project.go

62 lines
1.1 KiB
Go
Raw Normal View History

2016-08-03 08:28:58 +00:00
package realize
import (
"time"
"os/exec"
"os"
"bytes"
)
type Project struct {
reload time.Time
Name string `yaml:"app_name,omitempty"`
Path string `yaml:"app_path,omitempty"`
Main string `yaml:"app_main,omitempty"`
Run bool `yaml:"app_run,omitempty"`
Bin bool `yaml:"app_bin,omitempty"`
Build bool `yaml:"app_build,omitempty"`
Watcher Watcher `yaml:"app_watcher,omitempty"`
}
func GoRun () error{
return nil
}
func (p *Project) GoBuild() error{
var out bytes.Buffer
base, _ := os.Getwd()
2016-08-03 14:46:36 +00:00
path := base + p.Path
// create bin dir
if _, err := os.Stat(path + "bin"); err != nil {
if err = os.Mkdir(path + "bin", 0777); err != nil{
2016-08-03 16:49:17 +00:00
return err
2016-08-03 14:46:36 +00:00
}
}
2016-08-03 16:49:17 +00:00
2016-08-03 14:46:36 +00:00
build := exec.Command("go", "build", path + p.Main)
build.Dir = path + "bin"
2016-08-03 08:28:58 +00:00
build.Stdout = &out
if err := build.Run(); err != nil {
return err
}
return nil
}
2016-08-03 16:49:17 +00:00
func (p *Project) GoInstall() error{
var out bytes.Buffer
base, _ := os.Getwd()
path := base
build := exec.Command("go", "install")
build.Dir = path
build.Stdout = &out
if err := build.Run(); err != nil {
return err
}
2016-08-03 08:28:58 +00:00
return nil
}
func Stop() error{
return nil
}