chore: automate Matrix42 package build

This commit is contained in:
Meik
2026-06-26 16:58:15 +02:00
parent 3345365778
commit 36181e6462
51 changed files with 7336 additions and 6 deletions

View 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"

View File

@@ -13,6 +13,8 @@
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<M42ExtensionId>6673a25d-33d6-4072-91d9-abed4be1a966</M42ExtensionId>
<M42AssemblyPattern>C4ITF4SD*.*</M42AssemblyPattern>
<M42PackageVersion>1.4.0.4</M42PackageVersion>
<M42BuildPackage>true</M42BuildPackage>
</PropertyGroup>
<ItemGroup>

View File

@@ -1,9 +1,13 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<M42BasePackageAssembliesDir Condition="'$(M42BasePackageAssembliesDir)' == ''">$(MSBuildProjectDirectory)\BasePackage\Assemblies\</M42BasePackageAssembliesDir>
<M42RootAssembliesDir Condition="'$(M42RootAssembliesDir)' == '' AND '$(M42ExtensionId)' != ''">$(MSBuildProjectDirectory)\Root\InstalledPackages\Assemblies\$(M42ExtensionId)\</M42RootAssembliesDir>
<M42BasePackageAssembliesDir Condition="'$(M42BasePackageAssembliesDir)' == ''">$(MSBuildProjectDirectory)\BasePackage\Assemblies</M42BasePackageAssembliesDir>
<M42RootAssembliesDir Condition="'$(M42RootAssembliesDir)' == '' AND '$(M42ExtensionId)' != ''">$(MSBuildProjectDirectory)\Root\InstalledPackages\Assemblies\$(M42ExtensionId)</M42RootAssembliesDir>
<M42AssemblyPattern Condition="'$(M42AssemblyPattern)' == ''">$(MSBuildProjectName)*.*</M42AssemblyPattern>
<M42DefaultRids Condition="'$(M42DefaultRids)' == ''">win-x64;linux-x64</M42DefaultRids>
<M42PackageName Condition="'$(M42PackageName)' == ''">C4IT - F4SD M42 ESM Integration Configuration Package</M42PackageName>
<M42PackageTemplateDir Condition="'$(M42PackageTemplateDir)' == ''">$(MSBuildProjectDirectory)\..\PackageTemplate</M42PackageTemplateDir>
<M42PackageOutputRoot Condition="'$(M42PackageOutputRoot)' == ''">$(MSBuildProjectDirectory)\..\artifacts</M42PackageOutputRoot>
<M42PackageBuildScript Condition="'$(M42PackageBuildScript)' == ''">$(MSBuildProjectDirectory)\BuildM42Package.ps1</M42PackageBuildScript>
</PropertyGroup>
<Target Name="M42_BuildAllRids"
@@ -49,15 +53,28 @@
<_M42Rid Include="$(TargetDir)**\$(M42AssemblyPattern)" />
</ItemGroup>
<MakeDir Directories="$(M42BasePackageAssembliesDir)$(RuntimeIdentifier)" />
<MakeDir Directories="$(M42RootAssembliesDir)$(RuntimeIdentifier)" Condition="'$(M42RootAssembliesDir)' != ''" />
<MakeDir Directories="$(M42BasePackageAssembliesDir)\$(RuntimeIdentifier)" />
<MakeDir Directories="$(M42RootAssembliesDir)\$(RuntimeIdentifier)" Condition="'$(M42RootAssembliesDir)' != ''" />
<Copy SourceFiles="@(_M42Rid)"
DestinationFolder="$(M42BasePackageAssembliesDir)$(RuntimeIdentifier)\%(RecursiveDir)"
DestinationFolder="$(M42BasePackageAssembliesDir)\$(RuntimeIdentifier)\%(RecursiveDir)"
SkipUnchangedFiles="true" />
<Copy SourceFiles="@(_M42Rid)"
DestinationFolder="$(M42RootAssembliesDir)$(RuntimeIdentifier)\%(RecursiveDir)"
DestinationFolder="$(M42RootAssembliesDir)\$(RuntimeIdentifier)\%(RecursiveDir)"
SkipUnchangedFiles="true"
Condition="'$(M42RootAssembliesDir)' != ''" />
</Target>
<Target Name="M42_BuildPackage"
AfterTargets="Build"
Condition="'$(RuntimeIdentifier)' == '' AND '$(M42BuildPackage)' == 'true'">
<Error Condition="'$(M42PackageVersion)' == ''"
Text="M42PackageVersion is required when M42BuildPackage=true." />
<Error Condition="!Exists('$(M42PackageTemplateDir)\package.json')"
Text="M42 package template not found: $(M42PackageTemplateDir)" />
<Error Condition="!Exists('$(M42BasePackageAssembliesDir)\C4ITF4SDM42WebApi.dll')"
Text="M42 base package assemblies are missing: $(M42BasePackageAssembliesDir)" />
<Exec Command="powershell.exe -NoProfile -ExecutionPolicy Bypass -File &quot;$(M42PackageBuildScript)&quot; -TemplateDir &quot;$(M42PackageTemplateDir)&quot; -AssembliesDir &quot;$(M42BasePackageAssembliesDir)&quot; -OutputRoot &quot;$(M42PackageOutputRoot)&quot; -PackageName &quot;$(M42PackageName)&quot; -PackageVersion &quot;$(M42PackageVersion)&quot;" />
</Target>
</Project>