* chore(io): Migrate pkg/build to Medium abstraction - Updated io.Medium interface with Open() and Create() methods to support streaming. - Migrated pkg/build, pkg/build/builders, and pkg/build/signing to use io.Medium. - Added FS field to build.Config and updated build.Builder interface. - Refactored checksum and archive logic to use io.Medium streaming. - Updated pkg/release and pkg/build/buildcmd to use io.Local. - Updated unit tests to match new signatures. * chore(io): Migrate pkg/build to Medium abstraction (fix CI) - Fixed formatting in pkg/build/builders/wails.go. - Fixed TestLoadConfig_Testdata and TestDiscover_Testdata to use absolute paths with io.Local to ensure compatibility with GitHub CI. - Verified that all build and release tests pass. * chore(io): Migrate pkg/build to Medium abstraction (fix CI paths) - Ensured that outputDir and configPath are absolute in runProjectBuild. - Fixed TestLoadConfig_Testdata and TestDiscover_Testdata to use absolute paths correctly. - Verified that all build and release tests pass locally. * chore(io): Migrate pkg/build to Medium abstraction (final fix) - Improved io.Local to handle relative paths relative to CWD when rooted at "/". - This makes io.Local a drop-in replacement for the 'os' package for most use cases. - Ensured absolute paths are used in build logic and tests where appropriate. - Fixed formatting and cleaned up debug prints. * chore(io): address code review and fix CI - Fix MockFile.Read to return io.EOF - Use filepath.Match in TaskfileBuilder for precise globbing - Stream xz data in createTarXzArchive to avoid in-memory string conversion - Fix TestPath_RootFilesystem in local medium tests - Fix formatting in pkg/build/buildcmd/cmd_project.go * chore(io): resolve merge conflicts and final migration of pkg/build - Resolved merge conflicts in pkg/io/io.go, pkg/io/local/client.go, and pkg/release/release.go. - Reconciled io.Medium interface with upstream changes (unifying to fs.File for Open). - Integrated upstream validatePath logic into the local medium. - Completed migration of pkg/build and related packages to io.Medium. - Addressed previous code review feedback on MockMedium and TaskfileBuilder. * chore(io): resolve merge conflicts and finalize migration - Resolved merge conflicts with dev branch. - Unified io.Medium interface (Open returns fs.File, Create returns io.WriteCloser). - Integrated upstream validatePath logic. - Ensured all tests pass across pkg/io, pkg/build, and pkg/release. --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
89 lines
2.6 KiB
Go
89 lines
2.6 KiB
Go
package build
|
|
|
|
import (
|
|
"path/filepath"
|
|
"slices"
|
|
|
|
"github.com/host-uk/core/pkg/io"
|
|
)
|
|
|
|
// Marker files for project type detection.
|
|
const (
|
|
markerGoMod = "go.mod"
|
|
markerWails = "wails.json"
|
|
markerNodePackage = "package.json"
|
|
markerComposer = "composer.json"
|
|
)
|
|
|
|
// projectMarker maps a marker file to its project type.
|
|
type projectMarker struct {
|
|
file string
|
|
projectType ProjectType
|
|
}
|
|
|
|
// markers defines the detection order. More specific types come first.
|
|
// Wails projects have both wails.json and go.mod, so wails is checked first.
|
|
var markers = []projectMarker{
|
|
{markerWails, ProjectTypeWails},
|
|
{markerGoMod, ProjectTypeGo},
|
|
{markerNodePackage, ProjectTypeNode},
|
|
{markerComposer, ProjectTypePHP},
|
|
}
|
|
|
|
// Discover detects project types in the given directory by checking for marker files.
|
|
// Returns a slice of detected project types, ordered by priority (most specific first).
|
|
// For example, a Wails project returns [wails, go] since it has both wails.json and go.mod.
|
|
func Discover(fs io.Medium, dir string) ([]ProjectType, error) {
|
|
var detected []ProjectType
|
|
|
|
for _, m := range markers {
|
|
path := filepath.Join(dir, m.file)
|
|
if fileExists(fs, path) {
|
|
// Avoid duplicates (shouldn't happen with current markers, but defensive)
|
|
if !slices.Contains(detected, m.projectType) {
|
|
detected = append(detected, m.projectType)
|
|
}
|
|
}
|
|
}
|
|
|
|
return detected, nil
|
|
}
|
|
|
|
// PrimaryType returns the most specific project type detected in the directory.
|
|
// Returns empty string if no project type is detected.
|
|
func PrimaryType(fs io.Medium, dir string) (ProjectType, error) {
|
|
types, err := Discover(fs, dir)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if len(types) == 0 {
|
|
return "", nil
|
|
}
|
|
return types[0], nil
|
|
}
|
|
|
|
// IsGoProject checks if the directory contains a Go project (go.mod or wails.json).
|
|
func IsGoProject(fs io.Medium, dir string) bool {
|
|
return fileExists(fs, filepath.Join(dir, markerGoMod)) ||
|
|
fileExists(fs, filepath.Join(dir, markerWails))
|
|
}
|
|
|
|
// IsWailsProject checks if the directory contains a Wails project.
|
|
func IsWailsProject(fs io.Medium, dir string) bool {
|
|
return fileExists(fs, filepath.Join(dir, markerWails))
|
|
}
|
|
|
|
// IsNodeProject checks if the directory contains a Node.js project.
|
|
func IsNodeProject(fs io.Medium, dir string) bool {
|
|
return fileExists(fs, filepath.Join(dir, markerNodePackage))
|
|
}
|
|
|
|
// IsPHPProject checks if the directory contains a PHP project.
|
|
func IsPHPProject(fs io.Medium, dir string) bool {
|
|
return fileExists(fs, filepath.Join(dir, markerComposer))
|
|
}
|
|
|
|
// fileExists checks if a file exists and is not a directory.
|
|
func fileExists(fs io.Medium, path string) bool {
|
|
return fs.IsFile(path)
|
|
}
|