83 lines
3.1 KiB
PowerShell
83 lines
3.1 KiB
PowerShell
param(
|
|
[string]$OutputPath = (Join-Path $PSScriptRoot "release-optima"),
|
|
[ValidateSet("Debug", "Release")]
|
|
[string]$Configuration = "Release",
|
|
[ValidateSet("x86", "x64")]
|
|
[string]$Architecture = "x86"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$env:DOTNET_CLI_HOME = $PSScriptRoot
|
|
$env:APPDATA = $PSScriptRoot
|
|
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = "1"
|
|
$env:DOTNET_CLI_TELEMETRY_OPTOUT = "1"
|
|
|
|
$dotnet = (Get-Command dotnet -ErrorAction Stop).Source
|
|
|
|
$project = Join-Path $PSScriptRoot "src\SmartB2B.Optima.Service\SmartB2B.Optima.Service.csproj"
|
|
$daemonSource = Join-Path $PSScriptRoot "daemon-optima"
|
|
$winSwSource = Resolve-Path (Join-Path $daemonSource "smartb2bsync-optima.exe")
|
|
$output = [System.IO.Path]::GetFullPath($OutputPath)
|
|
$workspace = [System.IO.Path]::GetFullPath($PSScriptRoot)
|
|
$daemonOutput = Join-Path $output "daemon"
|
|
$runtimeIdentifier = "win-$Architecture"
|
|
|
|
if (-not $output.StartsWith($workspace, [StringComparison]::OrdinalIgnoreCase) -or
|
|
$output -eq $workspace -or
|
|
$output.Length -lt 10) {
|
|
throw "Niebezpieczna ścieżka wyjściowa: $output"
|
|
}
|
|
|
|
if (Test-Path -LiteralPath $output) {
|
|
Remove-Item -LiteralPath $output -Recurse -Force
|
|
}
|
|
|
|
New-Item -ItemType Directory -Force -Path $output | Out-Null
|
|
New-Item -ItemType Directory -Force -Path $daemonOutput | Out-Null
|
|
|
|
& $dotnet publish $project -c $Configuration -r $runtimeIdentifier --self-contained true -p:PlatformTarget=$Architecture -o $output
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Publikowanie usługi Optimy nie powiodło się."
|
|
}
|
|
|
|
Copy-Item $winSwSource (Join-Path $daemonOutput "smartb2bsync-optima.exe") -Force
|
|
Copy-Item (Join-Path $daemonSource "smartb2bsync-optima.xml") $daemonOutput -Force
|
|
Copy-Item (Join-Path $daemonSource "install.cmd") $daemonOutput -Force
|
|
Copy-Item (Join-Path $daemonSource "uninstall.cmd") $daemonOutput -Force
|
|
|
|
$downloadBaseUrl = "https://demo.smartb2b.eu/files/smartb2b-sync-optima/"
|
|
$manifestPath = Join-Path $daemonOutput "smartb2bsync-optima.xml"
|
|
[xml]$manifest = Get-Content -Raw $manifestPath
|
|
$packagedFiles = @(
|
|
Get-ChildItem -Recurse -File $output |
|
|
ForEach-Object { $_.FullName.Substring($output.Length).TrimStart('\') } |
|
|
Where-Object { $_ -ne "daemon\smartb2bsync-optima.exe" } |
|
|
Sort-Object
|
|
)
|
|
|
|
foreach ($relativePath in $packagedFiles) {
|
|
$download = $manifest.CreateElement("download")
|
|
$urlPath = $relativePath.Replace('\', '/')
|
|
$destination = if ($relativePath.StartsWith("daemon\", [StringComparison]::OrdinalIgnoreCase)) {
|
|
"%BASE%\" + $relativePath.Substring("daemon\".Length)
|
|
} else {
|
|
"%BASE%\..\" + $relativePath
|
|
}
|
|
$download.SetAttribute("from", $downloadBaseUrl + $urlPath)
|
|
$download.SetAttribute("to", $destination)
|
|
$download.SetAttribute("failOnError", "false")
|
|
[void]$manifest.service.AppendChild($download)
|
|
}
|
|
|
|
$settings = [System.Xml.XmlWriterSettings]::new()
|
|
$settings.Indent = $true
|
|
$settings.Encoding = [System.Text.UTF8Encoding]::new($false)
|
|
$writer = [System.Xml.XmlWriter]::Create($manifestPath, $settings)
|
|
try {
|
|
$manifest.Save($writer)
|
|
} finally {
|
|
$writer.Dispose()
|
|
}
|
|
|
|
Write-Host "Gotowa usługa Optimy (self-contained $runtimeIdentifier): $output"
|