mirror of
https://github.com/beego/bee.git
synced 2024-11-21 23:50:54 +00:00
Only contents in "CompareExcept" are excluded during comparison
This commit is contained in:
parent
174d2ab2e8
commit
a9d3de0872
@ -6,6 +6,8 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var CompareExcept = []string{"@BeeGenerateTime"}
|
||||||
|
|
||||||
func (c *Container) GenConfig() {
|
func (c *Container) GenConfig() {
|
||||||
if utils.IsExist(c.BeegoProFile) {
|
if utils.IsExist(c.BeegoProFile) {
|
||||||
beeLogger.Log.Fatalf("beego pro toml exist")
|
beeLogger.Log.Fatalf("beego pro toml exist")
|
||||||
|
@ -130,7 +130,8 @@ func (r *RenderFile) Exec(name string) {
|
|||||||
}
|
}
|
||||||
// Replace or create when content changes
|
// Replace or create when content changes
|
||||||
output := []byte(buf)
|
output := []byte(buf)
|
||||||
if r.Option.EnableFormat && filepath.Ext(r.FlushFile) == ".go" {
|
ext := filepath.Ext(r.FlushFile)
|
||||||
|
if r.Option.EnableFormat && ext == ".go" {
|
||||||
// format code
|
// format code
|
||||||
var bts []byte
|
var bts []byte
|
||||||
bts, err = format.Source([]byte(buf))
|
bts, err = format.Source([]byte(buf))
|
||||||
@ -141,7 +142,7 @@ func (r *RenderFile) Exec(name string) {
|
|||||||
output = bts
|
output = bts
|
||||||
}
|
}
|
||||||
|
|
||||||
if FileContentChange(orgContent,output) {
|
if FileContentChange(orgContent,output,GetSeg(ext)) {
|
||||||
err = r.write(r.FlushFile, output)
|
err = r.write(r.FlushFile, output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
beeLogger.Log.Fatalf("Could not create file: %s", err)
|
beeLogger.Log.Fatalf("Could not create file: %s", err)
|
||||||
|
@ -80,11 +80,7 @@ func (c *RenderFile) write(filename string, buf []byte) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isNeedOverwrite(fileName string) (flag bool) {
|
func isNeedOverwrite(fileName string) (flag bool) {
|
||||||
seg := "//"
|
seg := GetSeg(filepath.Ext(fileName))
|
||||||
ext := filepath.Ext(fileName)
|
|
||||||
if ext == ".sql" {
|
|
||||||
seg = "--"
|
|
||||||
}
|
|
||||||
|
|
||||||
f, err := os.Open(fileName)
|
f, err := os.Open(fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -190,21 +186,12 @@ func getModelType(orm string) (inputType, goType, mysqlType, tag string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func FileContentChange(org,new []byte) bool {
|
func FileContentChange(org,new []byte, seg string) bool {
|
||||||
if len(org) == 0 {
|
if len(org) == 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
var orgContent,newContent string
|
orgContent := GetFilterContent(string(org),seg)
|
||||||
for i, s := range strings.Split(string(org), "\n") {
|
newContent := GetFilterContent(string(org),string(new))
|
||||||
if i > 1 {
|
|
||||||
orgContent += s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for i, s := range strings.Split(string(new), "\n") {
|
|
||||||
if i > 1 {
|
|
||||||
newContent += s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
orgMd5 := md5.Sum([]byte(orgContent))
|
orgMd5 := md5.Sum([]byte(orgContent))
|
||||||
newMd5:= md5.Sum([]byte(newContent))
|
newMd5:= md5.Sum([]byte(newContent))
|
||||||
if orgMd5 != newMd5 {
|
if orgMd5 != newMd5 {
|
||||||
@ -213,3 +200,29 @@ func FileContentChange(org,new []byte) bool {
|
|||||||
beeLogger.Log.Infof("File has no change in the content")
|
beeLogger.Log.Infof("File has no change in the content")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetFilterContent(content string, seg string) string {
|
||||||
|
res := ""
|
||||||
|
for _, s := range strings.Split(content, "\n") {
|
||||||
|
s = strings.TrimSpace(strings.TrimPrefix(s, seg))
|
||||||
|
var have = false
|
||||||
|
for _,except := range CompareExcept{
|
||||||
|
if strings.HasPrefix(s, except) {
|
||||||
|
have = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !have {
|
||||||
|
res += s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetSeg(ext string) string {
|
||||||
|
switch ext {
|
||||||
|
case ".sql":
|
||||||
|
return "--"
|
||||||
|
default:
|
||||||
|
return "//"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user