agent/pkg/setup/detect.go
Snider 5628abcc7f refactor: flatten go/ subdir, migrate to dappco.re/go/agent, restore process service
- Module path: dappco.re/go/agent
- Core import: dappco.re/go/core v0.4.7
- Process service re-enabled with new Core API
- Plugin bumped to v0.11.0
- Directory flattened from go/ to root

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-21 11:12:40 +00:00

59 lines
1.3 KiB
Go

// SPDX-License-Identifier: EUPL-1.2
// Package setup provides workspace setup and scaffolding using lib templates.
package setup
import (
"os"
"path/filepath"
)
// ProjectType identifies what kind of project lives at a path.
type ProjectType string
const (
TypeGo ProjectType = "go"
TypePHP ProjectType = "php"
TypeNode ProjectType = "node"
TypeWails ProjectType = "wails"
TypeUnknown ProjectType = "unknown"
)
// Detect identifies the project type from files present at the given path.
func Detect(path string) ProjectType {
checks := []struct {
file string
projType ProjectType
}{
{"wails.json", TypeWails},
{"go.mod", TypeGo},
{"composer.json", TypePHP},
{"package.json", TypeNode},
}
for _, c := range checks {
if _, err := os.Stat(filepath.Join(path, c.file)); err == nil {
return c.projType
}
}
return TypeUnknown
}
// DetectAll returns all project types found at the path (polyglot repos).
func DetectAll(path string) []ProjectType {
var types []ProjectType
all := []struct {
file string
projType ProjectType
}{
{"go.mod", TypeGo},
{"composer.json", TypePHP},
{"package.json", TypeNode},
{"wails.json", TypeWails},
}
for _, c := range all {
if _, err := os.Stat(filepath.Join(path, c.file)); err == nil {
types = append(types, c.projType)
}
}
return types
}