1
0
mirror of https://github.com/beego/bee.git synced 2024-11-24 03:20:55 +00:00

add Beefily yml

This commit is contained in:
Sergey Lanzman 2016-07-23 02:37:20 +03:00
parent b022ab3277
commit 834f346bff
2 changed files with 43 additions and 14 deletions

15
Beefile Normal file
View File

@ -0,0 +1,15 @@
version: 0
gopm:
enable: false
install: false
go_install: false
watch_ext: []
dir_structure:
watch_all: false
controllers: ""
models: ""
others: []
cmd_args: []
envs: []
database:
driver: "mysql"

42
conf.go
View File

@ -16,7 +16,10 @@ package main
import ( import (
"encoding/json" "encoding/json"
"io/ioutil"
"os" "os"
"gopkg.in/yaml.v2"
) )
const CONF_VER = 0 const CONF_VER = 0
@ -50,20 +53,20 @@ var conf struct {
Install bool Install bool
} }
// Indicates whether execute "go install" before "go build". // Indicates whether execute "go install" before "go build".
GoInstall bool `json:"go_install"` GoInstall bool `json:"go_install" yaml:"go_install"`
WatchExt []string `json:"watch_ext"` WatchExt []string `json:"watch_ext" yaml:"watch_ext"`
DirStruct struct { DirStruct struct {
WatchAll bool `json:"watch_all"` WatchAll bool `json:"watch_all" yaml:"watch_all"`
Controllers string Controllers string
Models string Models string
Others []string // Other directories. Others []string // Other directories.
} `json:"dir_structure"` } `json:"dir_structure" yaml:"dir_structure"`
CmdArgs []string `json:"cmd_args"` CmdArgs []string `json:"cmd_args" yaml:"cmd_args"`
Envs []string Envs []string
Bale struct { Bale struct {
Import string Import string
Dirs []string Dirs []string
IngExt []string `json:"ignore_ext"` IngExt []string `json:"ignore_ext" yaml:"ignore_ext"`
} }
Database struct { Database struct {
Driver string Driver string
@ -73,14 +76,9 @@ var conf struct {
// loadConfig loads customized configuration. // loadConfig loads customized configuration.
func loadConfig() error { func loadConfig() error {
foundConf := false
f, err := os.Open("bee.json") f, err := os.Open("bee.json")
if err != nil { if err == nil {
// Use default.
err = json.Unmarshal([]byte(defaultConf), &conf)
if err != nil {
return err
}
} else {
defer f.Close() defer f.Close()
ColorLog("[INFO] Detected bee.json\n") ColorLog("[INFO] Detected bee.json\n")
d := json.NewDecoder(f) d := json.NewDecoder(f)
@ -88,8 +86,24 @@ func loadConfig() error {
if err != nil { if err != nil {
return err return err
} }
foundConf = true
}
byml, erryml := ioutil.ReadFile("Beefile")
if erryml == nil {
ColorLog("[INFO] Detected Beefile\n")
err = yaml.Unmarshal(byml, &conf)
if err != nil {
return err
}
foundConf = true
}
if !foundConf {
// Use default.
err = json.Unmarshal([]byte(defaultConf), &conf)
if err != nil {
return err
}
} }
// Check format version. // Check format version.
if conf.Version != CONF_VER { if conf.Version != CONF_VER {
ColorLog("[WARN] Your bee.json is out-of-date, please update!\n") ColorLog("[WARN] Your bee.json is out-of-date, please update!\n")