mirror of
https://github.com/opbnq-q/nto-cli.git
synced 2025-12-06 20:20:34 +07:00
46 lines
894 B
Go
46 lines
894 B
Go
package utils
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func FindFrontendPath() string {
|
|
currentPath, err := os.Getwd()
|
|
if err != nil {
|
|
log.Fatalf("Failed to find path for frontend: %s", err)
|
|
}
|
|
|
|
var dirs []string
|
|
for currentPath != filepath.VolumeName(currentPath)+string(os.PathSeparator) {
|
|
dir, file := filepath.Split(currentPath)
|
|
if file != "" {
|
|
dirs = append([]string{file}, dirs...)
|
|
}
|
|
currentPath = filepath.Clean(dir)
|
|
}
|
|
|
|
if len(dirs) < 2 || filepath.Join(dirs[len(dirs)-2], dirs[len(dirs)-1]) != filepath.Join("frontend", "src") {
|
|
log.Fatalf("Run this program in frontend/ directory")
|
|
}
|
|
|
|
var path string
|
|
for i, dir := range dirs {
|
|
if dir == "frontend" {
|
|
break
|
|
}
|
|
if i > 0 {
|
|
path = filepath.Join(path, dir)
|
|
} else {
|
|
path = dir
|
|
}
|
|
}
|
|
|
|
if filepath.VolumeName(path) == "" {
|
|
path = filepath.Join(string(os.PathSeparator), path)
|
|
}
|
|
|
|
return path
|
|
}
|