ps/Modules/Alkami.PowerShell.SDK/Public/New-SDKSnapshot.ps1

111 lines
3.8 KiB
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
function New-SDKSnapshot {
<#
.SYNOPSIS
Capture the current Chocolatey package state of the local machine environment
.DESCRIPTION
This will create a Chocolatey .nuspec package manifest in the output directory passed by argument (defaults to "c:\alkamisdk\snapshots"). The metadata section will be largely empty, each team should fill in as necessary and then commit to their source code repository and keep the package fresh by manually adjusting the contents or using the snapshot command.<EFBFBD>
.PARAMETER Name
The name of the .nuspec file generated by this snapshot command. The package name will default to "alkami.machinesetup.sdk.[guid]" where [guid] is a randomly generated guid value.
.PARAMETER Path
The path defaults to "c:\alkamisdk\snapshots" if none is passed in
.OUTPUTS
A Chocolatey package manifest.
.NOTES
General notes
#>
[CmdletBinding()]
param(
[string] $Name,
[string] $Path
)
if(!$Path){
$Path = "C:\alkamisdk\snapshots"
}
if(!$Name){
$guid = (New-Guid).Guid;
$Name = "alkami-machinesetup-sdk-snapshot-$guid"
}
$snapshotPath = Join-Path $Path $Name;
$chocolateyPackages = & choco list -lo "Alkami"
$nuspecTemplate = $nuspecTemplate.replace("[[id]]", $Name);
$nuspecTemplate = $nuspecTemplate.replace("[[title]]", $Name + " (install)");
$nuspecXmlDoc = [Xml]($nuspecTemplate);
$depsEle = $nuspecXmlDoc.GetElementsByTagName("dependencies");
foreach($package in $chocolateyPackages) {
$packageName = $package.Split(' ')[0];
$version = $package.Split(' ')[1];
$append = $true;
if($packageName -match "Alkami"){
$versionAttribute = $nuspecXmlDoc.CreateAttribute("version");
$nameAttribute = $nuspecXmlDoc.CreateAttribute("id");
$nameAttribute.Value = $packageName;
$versionAttribute.Value = $version;
if($packageName -match "Alkami.MachineSetup"){
if($packageName -eq "Alkami.MachineSetup.SDK") {
$versionAttribute.Value = "[$version]";
$append = $false;
}
else {
continue;
}
}
$dependencyElement = $nuspecXmlDoc.CreateElement("dependency", "http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd");
$consume = $dependencyElement.SetAttributeNode($nameAttribute);
$consume = $dependencyElement.SetAttributeNode($versionAttribute);
if($append) {
$consume = $depsEle.AppendChild($dependencyElement);
}
else
{
$consume = $depsEle.PrependChild($dependencyElement);
}
}
}
if(!(Test-Path $Path)) {
New-Item -Path $Path -ItemType Directory
}
$consume = $nuspecXmlDoc.Save((Join-Path $Path "$Name.nuspec"));
}
$nuspecTemplate = @"
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>[[id]]</id>
<version>`$version$</version>
<title>[[title]]</title>
<authors>Alkami Technology, Inc.</authors>
<owners>Alkami Technology, Inc.</owners>
<licenseUrl>http://alkami.com/files/orblicense.html</licenseUrl>
<projectUrl>https://confluence.alkami.com</projectUrl>
<iconUrl>https://www.alkami.com/files/alkamilogo75x75.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>This package was created from a snapshot of an SDK environment</description>
<releaseNotes />
<copyright>Copyright (c) $($(get-date).year) Alkami Technology, Inc.</copyright>
<tags>MachineSetup SDK TeamPackage</tags>
<dependencies>
</dependencies>
</metadata>
</package>
"@