Repository navigation
Expand file tree
/
Copy pathFileSystem.psm1
More file actions
83 lines (71 loc) · 3.25 KB
/
Copy pathFileSystem.psm1
File metadata and controls
83 lines (71 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# FULL # BEGIN FULL: Don't include this in the installer script
$PoshCodeModuleRoot = Get-Variable PSScriptRoot -ErrorAction SilentlyContinue | ForEach-Object { $_.Value }
if(!$PoshCodeModuleRoot) {
$PoshCodeModuleRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
}
# FULL # END FULL
function FindModule {
[CmdletBinding()]
param(
# Term to Search for (defaults to find "all" modules)
[string]$SearchTerm,
# Search for modules published by a particular author.
[string]$Author,
# Search for a specific module.
[string]$ModuleName,
[Parameter(Mandatory=$true)]
$Root
)
process {
$(
$RepositoryRoot = $Root
if((Test-Path $RepositoryRoot -Type Leaf) -or (Test-Path (Join-Path $PoshCodeModuleRoot $RepositoryRoot) -Type Leaf) -or (Test-Path (Join-Path $PoshCodeModuleRoot "$RepositoryRoot.psd1") -Type Leaf)) {
if(!(Test-Path $RepositoryRoot -Type Leaf)) { $RepositoryRoot = Join-Path $PoshCodeModuleRoot $RepositoryRoot }
if(!(Test-Path $RepositoryRoot -Type Leaf)) { $RepositoryRoot = "$RepositoryRoot.psd1" }
Write-Verbose "File Repository $RepositoryRoot"
# TODO: Check $Repository.LastUpdated and fetch from web
$Repository = Import-Metadata $RepositoryRoot
if($ModuleName) {
$Repository.Modules.$ModuleName
} else {
$Repository.Modules.Values |
Where-Object {
# Write-Verbose "File Repository Item Values: $($_.Values -split " |\\|/" -join ', ')"
$("$SearchTerm$Author"-eq"") -or
$(if($SearchTerm) {
($_.Values -Split " |\\|/" -like $SearchTerm) -or
($_.Values -like $SearchTerm)
}) -or
$(if($Author) { $_.Author.Contains($Author) })
}
}
} else {
Write-Verbose "Folder Repository $RepositoryRoot"
if(!$ModuleName) {
$Source = Join-Path $RepositoryRoot "*.psd1"
} else {
$Source = (Join-Path $RepositoryRoot "${ModuleName}*.psd1"),
(Join-Path $RepositoryRoot "*${ModuleName}*.psd1")
}
$OFS = ", "
Get-Item $Source |
Sort-Object -Unique |
Import-Metadata |
Where-Object {
# Write-Verbose "Folder Repository Item Values: $($_.Values -split " |\\|/" -join ', ')"
$("$SearchTerm$Author"-eq"") -or
$(if($SearchTerm) {
($_.Values -Split " |\\|/" -like $SearchTerm) -or
($_.Values -like $SearchTerm)
}) -or
$(if($Author) { $_.Author.Contains($Author) })
}
}
) | %{ New-Object PSObject -Property $_ } | % {
$_.pstypenames.Insert(0,'PoshCode.ModuleInfo')
$_.pstypenames.Insert(0,'PoshCode.Search.ModuleInfo')
$_.pstypenames.Insert(0,'PoshCode.Search.FileSystem.ModuleInfo')
Add-Member -Input $_ -Passthru -MemberType NoteProperty -Name Repository -Value @{ FileSystem = $Root }
}
}
}