81 lines
3.2 KiB
PowerShell
81 lines
3.2 KiB
PowerShell
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, '(?<!\r)\n', "`r`n")
|
|
[System.IO.File]::WriteAllText($Path, $content, [System.Text.UTF8Encoding]::new($true))
|
|
}
|
|
|
|
$templateDirFull = Normalize-FullPath $TemplateDir
|
|
$assembliesDirFull = Normalize-FullPath $AssembliesDir
|
|
$outputRootFull = Normalize-FullPath $OutputRoot
|
|
$packageDir = Join-Path $outputRootFull "$PackageName v$PackageVersion"
|
|
$zipPath = "$packageDir.zip"
|
|
|
|
if (-not (Test-Path -LiteralPath (Join-Path $templateDirFull 'package.json'))) {
|
|
throw "Package template not found: $templateDirFull"
|
|
}
|
|
|
|
if (-not (Test-Path -LiteralPath (Join-Path $assembliesDirFull 'C4ITF4SDM42WebApi.dll'))) {
|
|
throw "Package assemblies not found: $assembliesDirFull"
|
|
}
|
|
|
|
if (Test-Path -LiteralPath $packageDir) {
|
|
Remove-Item -LiteralPath $packageDir -Recurse -Force
|
|
}
|
|
|
|
if (Test-Path -LiteralPath $zipPath) {
|
|
Remove-Item -LiteralPath $zipPath -Force
|
|
}
|
|
|
|
New-Item -ItemType Directory -Path $packageDir -Force | Out-Null
|
|
Copy-Item -Path (Join-Path $templateDirFull '*') -Destination $packageDir -Recurse -Force
|
|
Copy-Item -Path $assembliesDirFull -Destination (Join-Path $packageDir 'Assemblies') -Recurse -Force
|
|
|
|
$packageJsonPath = Join-Path $packageDir 'package.json'
|
|
$packageJson = [System.IO.File]::ReadAllText($packageJsonPath)
|
|
$packageJson = [regex]::Replace($packageJson, '"Version"\s*:\s*"[^"]+"', "`"Version`": `"$PackageVersion`"")
|
|
$packageJson = [regex]::Replace($packageJson, '"LastUpdatedDate"\s*:\s*"[^"]+"', "`"LastUpdatedDate`": `"$(Get-Date -Format 'yyyy-MM-ddTHH:mm:ss')`"")
|
|
[System.IO.File]::WriteAllText($packageJsonPath, $packageJson, [System.Text.UTF8Encoding]::new($true))
|
|
|
|
$configurationDataPath = Join-Path $packageDir 'install\1010_Config_Data\02-01-0080 C4IT_F4SDConfigurationType.dat'
|
|
if (Test-Path -LiteralPath $configurationDataPath) {
|
|
$configurationData = [System.IO.File]::ReadAllText($configurationDataPath)
|
|
$configurationData = [regex]::Replace($configurationData, '<Version>[^<]+</Version>', "<Version>$PackageVersion</Version>", 1)
|
|
[System.IO.File]::WriteAllText($configurationDataPath, $configurationData, [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"
|