Last active
September 5, 2018 12:01
-
-
Save mkht/a2e031eb020f88892a18aba20f8ae4e9 to your computer and use it in GitHub Desktop.
Publish script for PowerShell Gallery
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
Param ( | |
[Parameter(Mandatory = $true)] | |
[ValidateNotNullOrEmpty()] | |
[string]$NugetApiKey, | |
[Parameter(Mandatory = $false)] | |
[ValidateNotNullOrEmpty()] | |
[string[]]$ExcludeDirs = @('.git', '.vscode'), | |
[Parameter(Mandatory = $false)] | |
[ValidateNotNullOrEmpty()] | |
[string[]]$ExcludeFiles = @('.gitignore'), | |
[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-Module -Path ./ -NuGetApiKey $NugetApiKey -Verbose -WhatIf:$WhatIf | |
} | |
finally { | |
Set-Location $ModuleDir | |
Remove-Item $Destination -Force -Recurse -ErrorAction Continue | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment