Files
nto-cli/utils/find_frontend_path.go
2025-03-08 20:54:22 +07:00

36 lines
718 B
Go

package utils
import (
"log"
"os"
"path/filepath"
"strings"
)
func FindFrontendPath() string {
currentPath, err := os.Getwd()
if err != nil {
log.Fatalf("Failed to find path for frontend: %s", err)
}
frontendSuffix := filepath.Join("frontend")
frontendSourceSuffix := filepath.Join("frontend", "src")
if strings.HasSuffix(currentPath, frontendSourceSuffix) {
return currentPath
}
var path string
if strings.HasSuffix(currentPath, frontendSuffix) {
path = filepath.Join(currentPath, "src")
} else {
path = filepath.Join(currentPath, frontendSourceSuffix)
}
if _, err := os.Stat(path); os.IsNotExist(err) {
log.Fatalf("Frontend source directory not found at %s", path)
}
return path
}