1
0
mirror of https://github.com/beego/bee.git synced 2025-06-27 00:20:21 +00:00

Revert "Compare content after formatting"

This reverts commit 174d2ab2e8.
This commit is contained in:
askuy
2020-07-27 13:09:56 +08:00
parent 59fa4ace1e
commit 0a2c7f0c57
2 changed files with 29 additions and 28 deletions

View File

@ -11,12 +11,13 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"strings"
"time"
)
// write to file
func (c *RenderFile) write(filename string, buf []byte) (err error) {
func (c *RenderFile) write(filename string, buf string) (err error) {
if utils.IsExist(filename) && !isNeedOverwrite(filename) {
return
}
@ -190,19 +191,34 @@ func getModelType(orm string) (inputType, goType, mysqlType, tag string) {
return
}
func FileContentChange(org,new []byte) bool {
if len(org) == 0 {
return true
func FileContentChange(org,new string) bool {
if org == "" {
return false
}
var orgContent,newContent string
for i, s := range strings.Split(string(org), "\n") {
if i > 1 {
orgContent += s
jump := false
// expect tab character and blank space and "import***"
reg := regexp.MustCompile("\\s+")
for i, s := range strings.Split(org, "\n") {
if s == "import (" {
jump = true
}
if jump && s == ")" {
jump = false
}
if i > 2 && !jump {
orgContent += reg.ReplaceAllString(s, "")
}
}
for i, s := range strings.Split(string(new), "\n") {
if i > 1 {
newContent += s
for i, s := range strings.Split(new, "\n") {
if s == "import (" {
jump = true
}
if jump && s == ")" {
jump = false
}
if i > 2 && !jump {
newContent += reg.ReplaceAllString(s, "")
}
}
orgMd5 := md5.Sum([]byte(orgContent))
@ -210,6 +226,5 @@ func FileContentChange(org,new []byte) bool {
if orgMd5 != newMd5 {
return true
}
beeLogger.Log.Infof("File has no change in the content")
return false
}