-
Notifications
You must be signed in to change notification settings - Fork 1
/
Publish-KnownFolders.ps1
47 lines (39 loc) · 1.38 KB
/
Publish-KnownFolders.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
46
47
[CmdletBinding(SupportsShouldProcess = $true)]
Param
(
[switch] $Production,
[PSCredential] $NuGetApiKeyCredential,
[string] $ModulePath = "$PSScriptRoot\Output\PSModules\KnownFolders"
)
Set-StrictMode -Version 5
$ErrorActionPreference = 'Stop'
$verboseValue = $VerbosePreference -ne 'SilentlyContinue'
if ($Production)
{
$repository = 'PSGallery'
}
else
{
$repository = 'JBMyGet'
$repositorySourceUrl = 'https://www.myget.org/F/jberezanski-psmodules/api/v2'
$repositoryPublishUrl = 'https://www.myget.org/F/jberezanski-psmodules/api/v2/package'
if ($null -eq (Get-PSRepository -Name $repository -ErrorAction SilentlyContinue))
{
if ($PSCmdlet.ShouldProcess("PSRepository $repository", 'Register'))
{
Register-PSRepository -Name $repository -SourceLocation $repositorySourceUrl -PublishLocation $repositoryPublishUrl -Verbose:$verboseValue
}
}
}
Resolve-Path -Path $ModulePath | Out-Null
if ($null -eq $NuGetApiKeyCredential)
{
$NuGetApiKeyCredential = Get-Credential -Credential 'API key'
}
$plainApiKey = $NuGetApiKeyCredential.GetNetworkCredential().Password
$whatIfValue = $true
if ($PSCmdlet.ShouldProcess($ModulePath, "Publish to repository $repository"))
{
$whatIfValue = $false
}
Publish-Module -Path $ModulePath -NuGetApiKey $plainApiKey -Repository $repository -Verbose:$verboseValue -WhatIf:$whatIfValue