Files
Sync-Enova365/publish.ps1

60 lines
2.1 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"
$existingConfigurationPath = Join-Path $output "config\enova.json"
$existingConfiguration = if (Test-Path -LiteralPath $existingConfigurationPath) {
[System.IO.File]::ReadAllText($existingConfigurationPath)
} else {
$null
}
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
if ($null -ne $existingConfiguration) {
[System.IO.File]::WriteAllText(
(Join-Path $output "config\enova.json"),
$existingConfiguration,
[System.Text.UTF8Encoding]::new($false))
}
Write-Host "Gotowa usługa: $output"