NN.PwshHelper.psm1

#Region './Private/Get-NuGetAccessToken.ps1' 0
function Get-NuGetAccessToken {
    param (
        [string]$accessTokenPath = "$env:USERPROFILE\.creds\NuGet\nuGetAccessToken.xml"
    )

    if (!(Test-Path $accessTokenPath)) {
        New-NuGetAccessToken
    }

    Import-Clixml $accessTokenPath | ConvertFrom-SecureString -AsPlainText
}
#EndRegion './Private/Get-NuGetAccessToken.ps1' 12
#Region './Private/New-NuGetAccessToken.ps1' 0
function New-NuGetAccessToken {
    param (
        [string]$accessTokenPath = "$env:USERPROFILE\.creds\NuGet\nuGetAccessToken.xml"
    )

    $apiKey = Read-Host "Enter NuGet API key" -AsSecureString

    #Create parent folders of the access token file
    $accessTokenDir = $accessTokenPath.Substring(0, $accessTokenPath.lastIndexOf('\'))
    if (!(Test-Path $accessTokenDir)) {
        $null = New-Item -ItemType Directory $accessTokenDir
    }

    #Create access token file
    $apiKey | Export-Clixml $accessTokenPath
}
#EndRegion './Private/New-NuGetAccessToken.ps1' 17
#Region './Public/Install-PwshRequiredModules.ps1' 0
function Install-PwshRequiredModules {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)][array]$ModuleNameArray
    )

    process {
        $ModuleNameArray.ForEach({
            if (Get-InstalledModule $_ -ErrorAction SilentlyContinue) {
                Import-Module $_ -Force
            } else {
                Install-Module $_ -Force
            }
        })
    }
}
#EndRegion './Public/Install-PwshRequiredModules.ps1' 17
#Region './Public/Invoke-PwshPublishModule.ps1' 0
function Invoke-PwshPublishModule {
    param (
        [Parameter(Mandatory)][string]$moduleName,
        [Parameter(Mandatory)][string]$modulePath
    )

    $allPsModulePath = ($env:PSModulePath -split ";")[0]
    $newFolderPath = "$allPsModulePath\$moduleName"
    
    if (Test-Path $newFolderPath) {
        Write-Error "Please remove the folder `"$newFolderPath`"." -ErrorAction Stop
    }

    $null = New-Item -ItemType Directory -Name $moduleName -Path $allPsModulePath -Force

    (Get-ChildItem $modulePath).FullName | ForEach-Object {
        Copy-Item -Destination $newFolderPath -Path $_
    }

    Publish-Module -Path $newFolderPath -NuGetApiKey $(Get-NuGetAccessToken)
    Remove-Item -Path $newFolderPath -Recurse
}
#EndRegion './Public/Invoke-PwshPublishModule.ps1' 23
#Region './Public/Write-Log.ps1' 0
function Write-Log {
    param (
        [Parameter(Mandatory)][string]$Message,
        [Parameter(Mandatory)][string]$Path
    )
    $logDir = $Path.Substring(0, $Path.lastIndexOf('\'))
    if (!(Test-Path $logDir)) {
        New-Item -ItemType Directory $logDir | Out-Null
    }

    $timeStamp = Get-Date -Format "dd/MM/yy hh:mm:ss"
    Add-Content -Path $Path -Value "$timeStamp $message"
}
#EndRegion './Public/Write-Log.ps1' 14