74 lines
4.1 KiB
PowerShell
74 lines
4.1 KiB
PowerShell
function Start-PPTSolutionRepack {
|
|
[CmdLetBinding()]
|
|
Param(
|
|
$Path = (Get-Location).Path,
|
|
[Alias('m')]
|
|
[switch]$Managed
|
|
)
|
|
|
|
begin {
|
|
|
|
$Path = @{
|
|
qualifier = (Split-Path -Path $Path -Qualifier)
|
|
parent = (Split-Path -Path $Path)
|
|
leaf = (Split-Path -Path $Path -Leaf)
|
|
path = $Path
|
|
pathBuild = (Join-Path -Path $Path -ChildPath 'Build')
|
|
pathConfig = (Join-Path -Path $Path -ChildPath 'Build\config.json')
|
|
sourcePath = (Join-Path -Path $PSScriptRoot -ChildPath 'source')
|
|
sourceConfig = (Join-Path -Path $PSScriptRoot -ChildPath 'source\config.ps1')
|
|
sourceIgnore = (Join-Path -Path $PSScriptRoot -ChildPath 'source\.gitignore')
|
|
}
|
|
|
|
$config = (Get-Content $Path.pathConfig | ConvertFrom-Json)
|
|
$env = ($config.env | ?{$_.name -eq $Environment})
|
|
|
|
function NameThatSolution () {
|
|
#Write-Host "┌───────────────────────────────────────────────────────────────┐" -ForegroundColor Green
|
|
#Write-Host "│" -ForegroundColor Green -NoNewLine; Write-Host "`t`t`tNAME THAT SOLUTION`t`t`t" -ForegroundColor Cyan -NoNewline; Write-Host "│" -ForegroundColor Green
|
|
#Write-Host "└───────────────────────────────────────────────────────────────┘" -ForegroundColor Green
|
|
do {
|
|
$solutionNameProvided = Read-Host -Prompt "Enter Solution Package name"
|
|
If($solutionNameProvided -match '\s*(\W+?)') {
|
|
Write-Host "We had to fix a few things with the Solution Package name provided [" -NoNewline -ForegroundColor Yellow
|
|
Write-Host "$($solutionNameProvided)" -NoNewLine -ForegroundColor White
|
|
Write-Host "]`nHope you're not too upset." -ForegroundColor Yellow
|
|
}
|
|
$solutionNewName = $solutionNameProvided -replace ('\s*(\W+?)', '')
|
|
Write-Host "`n$(If($solutionNameProvided -match '\s*(\W+?)'){"A little fixer upper: "}Else{"Solution Package Name:"})" -NoNewline -ForegroundColor Green
|
|
Write-Host "$($solutionNewName)" -ForegroundColor Magenta
|
|
$continueSolutionName = Read-Host -Prompt "$(If($solutionNameProvided -match '\s*(\W+?)'){"We good?"}Else{"Continue"}) (y/n)"
|
|
} while ($continueSolutionName -ne 'y' -or $continueSolutionName -ne 'Y')
|
|
#$Path.leaf = $solutionNewName
|
|
return $solutionNewName
|
|
}
|
|
|
|
}
|
|
|
|
process {
|
|
|
|
$Path.leaf = NameThatSolution
|
|
|
|
Write-Host "[ Info ] " -ForegroundColor Green -nonewline; write-host "Repacking $(If($Managed){'managed'}else{'unmanaged'}) solution used for deployment" -ForegroundColor Cyan
|
|
|
|
foreach ($msapp in (Get-ChildItem -Path (Join-Path -Path $Path.path -ChildPath 'CanvasApps') -Filter '*.msapp')) {
|
|
Write-Host "[ Info ] " -ForegroundColor Green -nonewline; write-host "Compiling $($msapp.basename.split('_')[1]) Binary Canvas Application" -ForegroundColor Cyan
|
|
Write-Host "[ Info ] " -ForegroundColor Green -nonewline; write-host "$($msapp.Fullname)" -ForegroundColor Cyan
|
|
$applicationManifest = $null
|
|
$applicationManifest = Get-ChildItem -Path (Join-Path -Path $Path.path -ChildPath "CanvasApps\src") -Filter "*_$($msapp.basename.split('_')[1])_*"
|
|
& $Global:pptConfig.pacPath canvas pack --msapp $msapp.Fullname --sources "$($applicationManifest.Fullname)"
|
|
}
|
|
|
|
& $Global:pptConfig.pacPath solution pack --zipfile "$($Path.path)\$($Path.leaf).zip" --folder $Path.path --processCanvasApps --packagetype $(If($Managed){'Managed'}else{'Unmanaged'}) --errorLevel Verbose
|
|
|
|
}
|
|
|
|
end {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# EXPORT ALIAS
|
|
New-Alias -Name repack -Value Start-PPTSolutionRepack -Description 'posh-PowerPlatformToolkit - Start-PPTSolutionRepack alias' -Force
|