feat: migrate 26eac54 state to Matrix42 26.1
This commit is contained in:
73
F4SDM42WebApi/BuildM42Package.ps1
Normal file
73
F4SDM42WebApi/BuildM42Package.ps1
Normal file
@@ -0,0 +1,73 @@
|
||||
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))
|
||||
|
||||
$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"
|
||||
Reference in New Issue
Block a user