ps/package.ps1

52 lines
1.7 KiB
PowerShell
Raw Normal View History

2023-05-30 22:55:40 -07:00
param([switch]$clean)
$chocoPath = (Join-Path $PSScriptRoot "choco")
## See notes below
$DEVOPS_Modules_ChocoOutputPathKey = "DEVOPS_Modules_ChocoOutputPath"
$DEVOPS_Modules_ChocoOutputPath = [System.Environment]::GetEnvironmentVariable($DEVOPS_Modules_ChocoOutputPathKey, "User")
if (!([string]::IsNullOrEmpty($DEVOPS_Modules_ChocoOutputPath))) {
$chocoPath = $DEVOPS_Modules_ChocoOutputPath
}
if (!(Test-Path $chocoPath)) {
(New-Item $chocoPath -ItemType Directory -Force) | Out-Null
}
if ($clean) {
Remove-Item -Path $chocoPath\*.nupkg -Force -ErrorAction SilentlyContinue | Out-Null
}
$nuspecPaths = (Get-ChildItem *.nuspec -Recurse)
foreach ($nuspecPath in $nuspecPaths) {
$folderPath = (Split-Path $nuspecPath);
$psdPath = (Join-Path $folderPath "*.psd1");
if (!(Test-Path $psdPath)) { continue; }
Write-Output "";
Write-Output "";
Write-Output "Packaging $folderPath";
$version = (((Get-Content $psdPath) | ? { $_.Trim().StartsWith('ModuleVersion') }) -split '=')[1].Trim().Replace("'","")
choco pack $nuspecPath --version $version --out $chocoPath
Write-Output "=================";
}
<#
If you want to override the address where these files are built-produced-to, add this to your profile:
C:\Users\<username>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
and update the target folder (in this case z:\choco)
$DEVOPS_Modules_ChocoOutputPathKey = "DEVOPS_Modules_ChocoOutputPath"
$DEVOPS_Modules_ChocoOutputPath = [System.Environment]::GetEnvironmentVariable($DEVOPS_Modules_ChocoOutputPathKey, "User")
if ([string]::IsNullOrEmpty($DEVOPS_Modules_ChocoOutputPath)) {
[System.Environment]::SetEnvironmentVariable($DEVOPS_Modules_ChocoOutputPathKey, "Z:\choco", "User")
}
#>