🎨 移除多余模块
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package ast
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/pkg/errors"
|
||||
"go/ast"
|
||||
"go/format"
|
||||
@@ -61,7 +60,7 @@ func (a *Base) Format(filename string, writer io.Writer, file *ast.File) error {
|
||||
|
||||
// RelativePath 绝对路径转相对路径
|
||||
func (a *Base) RelativePath(filePath string) string {
|
||||
server := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server)
|
||||
server := resolveServerRoot()
|
||||
hasServer := strings.Index(filePath, server)
|
||||
if hasServer != -1 {
|
||||
filePath = strings.TrimPrefix(filePath, server)
|
||||
@@ -73,9 +72,30 @@ func (a *Base) RelativePath(filePath string) string {
|
||||
|
||||
// AbsolutePath 相对路径转绝对路径
|
||||
func (a *Base) AbsolutePath(filePath string) string {
|
||||
server := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server)
|
||||
server := resolveServerRoot()
|
||||
keys := strings.Split(filePath, "/")
|
||||
filePath = filepath.Join(keys...)
|
||||
filePath = filepath.Join(server, filePath)
|
||||
return filePath
|
||||
}
|
||||
|
||||
func resolveProjectRoot() string {
|
||||
if cwd, err := os.Getwd(); err == nil {
|
||||
if filepath.Base(cwd) == "server" {
|
||||
return filepath.Dir(cwd)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(cwd, "server")); err == nil {
|
||||
return cwd
|
||||
}
|
||||
return cwd
|
||||
}
|
||||
return "."
|
||||
}
|
||||
|
||||
func resolveServerRoot() string {
|
||||
root := resolveProjectRoot()
|
||||
if filepath.Base(root) == "server" {
|
||||
return root
|
||||
}
|
||||
return filepath.Join(root, "server")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user