2026-03-09 13:13:30 +00:00
|
|
|
// Package detect identifies project types by examining filesystem markers.
|
|
|
|
|
package detect
|
|
|
|
|
|
2026-03-17 09:02:06 +00:00
|
|
|
import (
|
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
|
|
coreio "forge.lthn.ai/core/go-io"
|
|
|
|
|
)
|
2026-03-09 13:13:30 +00:00
|
|
|
|
|
|
|
|
// ProjectType identifies a project's language/framework.
|
|
|
|
|
type ProjectType string
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
Go ProjectType = "go"
|
|
|
|
|
PHP ProjectType = "php"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// IsGoProject returns true if dir contains a go.mod file.
|
|
|
|
|
func IsGoProject(dir string) bool {
|
2026-03-17 09:02:06 +00:00
|
|
|
return coreio.Local.Exists(filepath.Join(dir, "go.mod"))
|
2026-03-09 13:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IsPHPProject returns true if dir contains a composer.json file.
|
|
|
|
|
func IsPHPProject(dir string) bool {
|
2026-03-17 09:02:06 +00:00
|
|
|
return coreio.Local.Exists(filepath.Join(dir, "composer.json"))
|
2026-03-09 13:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DetectAll returns all detected project types in the directory.
|
|
|
|
|
func DetectAll(dir string) []ProjectType {
|
|
|
|
|
var types []ProjectType
|
|
|
|
|
if IsGoProject(dir) {
|
|
|
|
|
types = append(types, Go)
|
|
|
|
|
}
|
|
|
|
|
if IsPHPProject(dir) {
|
|
|
|
|
types = append(types, PHP)
|
|
|
|
|
}
|
|
|
|
|
return types
|
|
|
|
|
}
|