param(
[Parameter(Mandatory = $true)]
[string]$TemplateDir,
[Parameter(Mandatory = $true)]
[string]$AssembliesDir,
[Parameter(Mandatory = $true)]
[string]$OutputRoot,
[Parameter(Mandatory = $true)]
[string]$PackageName,
[Parameter(Mandatory = $true)]
[string]$PackageVersion
)
$ErrorActionPreference = 'Stop'
function Normalize-FullPath {
param([string]$Path)
return [System.IO.Path]::GetFullPath($Path)
}
function Normalize-TextFileLineEndings {
param([string]$Path)
$content = [System.IO.File]::ReadAllText($Path)
$content = [regex]::Replace($content, '(?[\s\S]*?)[^<]*()',
"`${1}$PackageVersion`${2}",
[System.Text.RegularExpressions.RegexOptions]::Singleline
)
if ($configData -notmatch "$([regex]::Escape($PackageVersion))") {
throw "Could not update C4IT_F4SDConfigurationType Version to $PackageVersion in $configDataPath"
}
[System.IO.File]::WriteAllText($configDataPath, $configData, [System.Text.UTF8Encoding]::new($true))
}
$textFileExtensions = @('.json', '.xml', '.dat', '.type', '.class', '.config', '.host')
Get-ChildItem -LiteralPath $packageDir -Recurse -File |
Where-Object { $textFileExtensions -contains $_.Extension.ToLowerInvariant() } |
ForEach-Object { Normalize-TextFileLineEndings $_.FullName }
Compress-Archive -Path (Join-Path $packageDir '*') -DestinationPath $zipPath -Force
Write-Host "Matrix42 package folder: $packageDir"
Write-Host "Matrix42 package zip: $zipPath"