-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.ps1
45 lines (35 loc) · 1.23 KB
/
publish.ps1
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
#Requires -Modules Microsoft.PowerShell.PSResourceGet
Param (
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$NugetApiKey,
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[string[]]$ExcludeDirs = @('.git', '.github', '.vscode', 'Tests', 'Examples'),
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[string[]]$ExcludeFiles = @('.gitignore', '.gitmodules', '.gitattributes'),
[switch]$WhatIf
)
$ModuleDir = $PSScriptRoot
$ModuleName = Split-Path $ModuleDir -Leaf
$MySelfName = Split-Path $PSCommandPath -Leaf
$Destination = Join-Path $env:TEMP $ModuleName
if (Test-Path $Destination) {
Remove-Item $Destination -Force -Recurse -ErrorAction Stop
}
if ($ExcludeDirs -notcontains '.git') {
$ExcludeDirs += '.git'
}
if ($ExcludeFiles -notcontains $MySelfName) {
$ExcludeFiles += $MySelfName
}
try {
robocopy $ModuleDir $Destination /MIR /XD $ExcludeDirs /XF $ExcludeFiles /NP > $null
Set-Location $Destination
Publish-PSResource -Path ./ -Repository PSGallery -ApiKey $NugetApiKey -Verbose -WhatIf:$WhatIf
}
finally {
Set-Location $ModuleDir
Remove-Item $Destination -Force -Recurse -ErrorAction Continue
}