ps/Modules/Alkami.DevOps.Operations/tools/chocolateyInstall.ps1

43 lines
1.7 KiB
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
[CmdletBinding()]
Param()
process {
$myCurrentPath = $PSScriptRoot;
Write-Verbose "Installing the Module from $myCurrentPath";
$parentPath = (Split-Path $myCurrentPath);
$systemModulePath = "C:\Program Files\WindowsPowerShell\Modules\";
$myModulePath = (Join-Path $parentPath "module");
$metadata = ([Xml](Get-Content (Join-Path $parentPath "*.nuspec"))).package.metadata;
$id = $metadata.id;
$version = $metadata.version -replace '-pre.+','';
$targetModulePath = (Join-Path $systemModulePath $id);
$targetModuleVersionPath = (Join-Path $targetModulePath $version);
if (Test-Path $targetModulePath) {
## If the target folder already existed, remove it, because we are re-installing this package, obviously
if (Test-Path $targetModuleVersionPath) {
Write-Warning "Found an already existing module at [$targetModuleVersionPath]!!"
Remove-Item $targetModuleVersionPath -Recurse -Force;
}
## Clear previous children for name conflicts
(Get-ChildItem $targetModulePath) | ForEach-Object {
Write-Information "Removing module located at [$_]";
Remove-Item $_.FullName -Recurse -Force;
}
}
Write-Host "Copying module $id to [$targetModuleVersionPath]";
Copy-Item $myModulePath -Destination $targetModuleVersionPath -Recurse -Force;
$resourcesFolder = (Join-Path -Path $parentPath -ChildPath "Resources")
if (Test-Path -Path $resourcesFolder) {
Write-Host "Copying resources folder for module $id to [$targetModuleVersionPath]"
Copy-Item -Path $resourcesFolder -Destination $targetModuleVersionPath -Recurse -Force
}
}