-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from aldrichtr/fix/project-directories
Find the project directories based on file type
- Loading branch information
Showing
8 changed files
with
257 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
function Find-ModuleManifest { | ||
<# | ||
.SYNOPSIS | ||
Find all module manifests in the given directory. | ||
#> | ||
[CmdletBinding()] | ||
param( | ||
# Specifies a path to one or more locations. | ||
[Parameter( | ||
Position = 0, | ||
ValueFromPipeline, | ||
ValueFromPipelineByPropertyName | ||
)] | ||
[Alias('PSPath')] | ||
[string[]]$Path | ||
) | ||
begin { | ||
Write-Debug "`n$('-' * 80)`n-- Begin $($MyInvocation.MyCommand.Name)`n$('-' * 80)" | ||
} | ||
process { | ||
$possibleManifests = Get-ChildItem @PSBoundParameters -Recurse -Filter "*.psd1" | ||
|
||
foreach ($possibleManifest in $possibleManifests) { | ||
try { | ||
$module = $possibleManifest | Import-Psd -Unsafe | ||
} catch { | ||
Write-Debug "$possibleManifest could not be imported" | ||
continue | ||
} | ||
if ($null -ne $module) { | ||
Write-Debug "Checking if $($possibleManifest.Name) is a manifest" | ||
if ( | ||
($module.Keys -contains 'ModuleVersion') -and | ||
($module.Keys -contains 'GUID') -and | ||
($module.Keys -contains 'PrivateData') | ||
) { | ||
$possibleManifest | Write-Output | ||
} else { | ||
Write-Debug "- Not a module manifest file" | ||
} | ||
} else { | ||
continue | ||
} | ||
} | ||
} | ||
end { | ||
Write-Debug "`n$('-' * 80)`n-- End $($MyInvocation.MyCommand.Name)`n$('-' * 80)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
function Find-SourceDirectory { | ||
<# | ||
.SYNOPSIS | ||
Find the directory that contains the project's source files | ||
#> | ||
[CmdletBinding()] | ||
param( | ||
) | ||
begin { | ||
Write-Debug "`n$('-' * 80)`n-- Begin $($MyInvocation.MyCommand.Name)`n$('-' * 80)" | ||
$ignoredDirectories = @('.build', '.stitch') | ||
$maximumNestedLevel = 4 | ||
} | ||
process { | ||
$root = Resolve-ProjectRoot | ||
Write-Debug "Looking for source directory in $root" | ||
|
||
$manifests = Find-ModuleManifest $root | ||
|
||
if ($manifests.Count -gt 0) { | ||
:manifest foreach ($manifest in $manifests) { | ||
$relativePath = [System.IO.Path]::GetRelativePath($root, $manifest.FullName) | ||
$parts = $relativePath -split [regex]::Escape([System.IO.Path]::DirectorySeparatorChar) | ||
Write-Debug "$($manifest.FullName) is $($parts.Count) levels below root" | ||
:parts switch ($parts.Count) { | ||
0 { | ||
throw "The path to $($manifest.FullName) is invalid" | ||
} | ||
default { | ||
if ($parts[0] -notin $ignoredDirectories) { | ||
|
||
if ($parts.Count -lt $maximumNestedLevel ) { | ||
Get-Item (Join-Path $root $parts[0] ) | Write-Output | ||
} else { | ||
Write-Debug "$($manifest.Name) is nested below maximum levels: $($parts.Count)" | ||
} | ||
} else { | ||
Write-Debug "$($parts[0]) is ignored" | ||
} | ||
continue manifest | ||
} | ||
} | ||
} | ||
} else { | ||
throw "No manifests found in project '$root'" | ||
} | ||
|
||
} | ||
end { | ||
Write-Debug "`n$('-' * 80)`n-- End $($MyInvocation.MyCommand.Name)`n$('-' * 80)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
function Find-TestDirectory { | ||
<# | ||
.SYNOPSIS | ||
Find the directory where tests are stored | ||
#> | ||
[CmdletBinding()] | ||
param( | ||
# Test file pattern | ||
[Parameter( | ||
)] | ||
[string]$TestsPattern = '*.Tests.ps1' | ||
) | ||
begin { | ||
Write-Debug "`n$('-' * 80)`n-- Begin $($MyInvocation.MyCommand.Name)`n$('-' * 80)" | ||
} | ||
process { | ||
$root = Resolve-ProjectRoot | ||
Write-Debug "Looking for test directory in $root" | ||
|
||
$testFiles = Find-TestFile $root -TestsPattern $TestsPattern | ||
$foundDirectories = [System.Collections.ArrayList]::new() | ||
|
||
if ($testFiles.Count -gt 0) { | ||
:testfile foreach ($testFile in $testFiles) { | ||
$relativePath = [System.IO.Path]::GetRelativePath($root, $testFile.FullName) | ||
$parts = $relativePath -split [regex]::Escape([System.IO.Path]::DirectorySeparatorChar) | ||
Write-Debug "$($testFile.FullName) is $($parts.Count) levels below root" | ||
:parts switch ($parts.Count) { | ||
0 { | ||
throw "The path to $($testFile.FullName) is invalid" | ||
} | ||
default { | ||
$possibleTestPath = (Join-Path $root $parts[0]) | ||
if ($possibleTestPath -notin $foundDirectories) { | ||
[void]$foundDirectories.Add($possibleTestPath) | ||
continue testfile | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
end { | ||
$foundDirectories | Foreach-Object { Get-Item $_ | Write-Output } | ||
Write-Debug "`n$('-' * 80)`n-- End $($MyInvocation.MyCommand.Name)`n$('-' * 80)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
function Find-TestFile { | ||
<# | ||
.SYNOPSIS | ||
Find files that contain tests | ||
#> | ||
[CmdletBinding()] | ||
param( | ||
# Specifies a path to one or more locations. | ||
[Parameter( | ||
Position = 0, | ||
ValueFromPipeline, | ||
ValueFromPipelineByPropertyName | ||
)] | ||
[Alias('PSPath')] | ||
[string[]]$Path, | ||
|
||
# Test file pattern | ||
[Parameter( | ||
)] | ||
[string]$TestsPattern = '*.Tests.ps1' | ||
) | ||
begin { | ||
Write-Debug "`n$('-' * 80)`n-- Begin $($MyInvocation.MyCommand.Name)`n$('-' * 80)" | ||
} | ||
process { | ||
$possibleTestFiles = Get-ChildItem -Path $Path -Recurse -File -Filter $TestsPattern | ||
|
||
foreach ($possibleTestFile in $possibleTestFiles) { | ||
Write-Debug "Checking $possibleTestFile for Pester tests" | ||
if ($possibleTestFile | Select-String '\s*Describe') { | ||
Write-Debug "- Has the 'Describe' keyword" | ||
$possibleTestFile | Write-Output | ||
} else { | ||
continue | ||
} | ||
} | ||
} | ||
end { | ||
Write-Debug "`n$('-' * 80)`n-- End $($MyInvocation.MyCommand.Name)`n$('-' * 80)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.