Private/Get-ProjectType.ps1
|
<# .SYNOPSIS Detects the project type from files in the current or specified directory. .DESCRIPTION Examines the directory for known project files and returns the detected ecosystem type. Detection order: .psd1 > .csproj > package.json > pyproject.toml > git tags .PARAMETER Path Directory to examine. Defaults to current directory. .OUTPUTS [PSCustomObject] with Type, File, and Description properties. #> function Get-ProjectType { [CmdletBinding()] [OutputType([PSCustomObject])] param( [Parameter()] [string]$Path = (Get-Location).Path ) # PowerShell module (.psd1) $psd1 = Get-ChildItem -Path $Path -Filter '*.psd1' -File | Select-Object -First 1 if ($psd1) { return [PSCustomObject]@{ Type = 'PowerShell' File = $psd1.FullName FileName = $psd1.Name Description = "PowerShell module manifest" } } # .NET project (.csproj) $csproj = Get-ChildItem -Path $Path -Filter '*.csproj' -File | Select-Object -First 1 if ($csproj) { return [PSCustomObject]@{ Type = 'DotNet' File = $csproj.FullName FileName = $csproj.Name Description = ".NET project" } } # Node.js (package.json) $packageJson = Join-Path $Path 'package.json' if (Test-Path $packageJson) { return [PSCustomObject]@{ Type = 'Node' File = $packageJson FileName = 'package.json' Description = "Node.js package" } } # Python (pyproject.toml) $pyproject = Join-Path $Path 'pyproject.toml' if (Test-Path $pyproject) { return [PSCustomObject]@{ Type = 'Python' File = $pyproject FileName = 'pyproject.toml' Description = "Python project" } } # Fallback: git tags try { $null = git -C $Path rev-parse --git-dir 2>$null if ($LASTEXITCODE -eq 0) { return [PSCustomObject]@{ Type = 'GitTag' File = $null FileName = $null Description = "Version from git tags only" } } } catch { } return [PSCustomObject]@{ Type = 'Unknown' File = $null FileName = $null Description = "No recognized project type detected" } } |