Files
Sync-Enova365/publish.ps1

66 lines
2.5 KiB
PowerShell

param(
[string]$OutputPath = (Join-Path $PSScriptRoot "release"),
[ValidateSet("Debug", "Release")]
[string]$Configuration = "Release"
)
$ErrorActionPreference = "Stop"
$env:DOTNET_CLI_HOME = $PSScriptRoot
$env:APPDATA = $PSScriptRoot
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = "1"
$env:DOTNET_CLI_TELEMETRY_OPTOUT = "1"
$bundledDotnet = Join-Path $PSScriptRoot "..\..\..\test1\.dotnet\dotnet.exe"
$dotnet = if (Test-Path -LiteralPath $bundledDotnet) {
(Resolve-Path $bundledDotnet).Path
} else {
(Get-Command dotnet -ErrorAction Stop).Source
}
$project = Join-Path $PSScriptRoot "src\SmartB2B.Enova.Service\SmartB2B.Enova.Service.csproj"
$daemonSource = Join-Path $PSScriptRoot "daemon"
$winSwSource = Resolve-Path (Join-Path $daemonSource "smartb2bsync-enova.exe")
$output = [System.IO.Path]::GetFullPath($OutputPath)
$daemonOutput = Join-Path $output "daemon"
if ($output -eq [System.IO.Path]::GetPathRoot($output) -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 --no-restore -o $output
if ($LASTEXITCODE -ne 0) {
throw "Publikowanie usługi nie powiodło się."
}
Copy-Item $winSwSource (Join-Path $daemonOutput "smartb2bsync-enova.exe") -Force
Copy-Item (Join-Path $daemonSource "smartb2bsync-enova.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-enova/"
[xml]$manifest = Get-Content -Raw (Join-Path $daemonOutput "smartb2bsync-enova.xml")
$downloadedFiles = @(
$manifest.service.download |
ForEach-Object { $_.from.Substring($downloadBaseUrl.Length).Replace('/', '\') } |
Sort-Object
)
$packagedFiles = @(
Get-ChildItem -Recurse -File $output |
ForEach-Object { $_.FullName.Substring($output.Length).TrimStart('\') } |
Where-Object { $_ -ne "daemon\smartb2bsync-enova.exe" } |
Sort-Object
)
$manifestDifferences = @(Compare-Object $packagedFiles $downloadedFiles)
if ($manifestDifferences.Count -ne 0) {
$details = $manifestDifferences | ForEach-Object { "$($_.SideIndicator) $($_.InputObject)" }
throw "Lista plików <download> nie odpowiada paczce:`n$($details -join "`n")"
}
Write-Host "Gotowa usługa: $output"