| | |
| | | param( |
| | | [string]$Configuration = "Release", |
| | | [string]$Runtime = "win-x64", |
| | | [string]$TargetRoot = "Y:\应用程序", |
| | | [string]$TargetRoot = "D:\lin\tools\Moli.Desktop", |
| | | [string]$AppName = "Moli.Desktop", |
| | | [switch]$SelfContained, |
| | | [switch]$SkipTests, |
| | |
| | | } |
| | | } |
| | | |
| | | function Get-RelativePathCompat { |
| | | param( |
| | | [Parameter(Mandatory = $true)] |
| | | [string]$BasePath, |
| | | [Parameter(Mandatory = $true)] |
| | | [string]$TargetPath |
| | | ) |
| | | |
| | | $baseFullPath = [System.IO.Path]::GetFullPath($BasePath).TrimEnd([System.IO.Path]::DirectorySeparatorChar, [System.IO.Path]::AltDirectorySeparatorChar) |
| | | $targetFullPath = [System.IO.Path]::GetFullPath($TargetPath).TrimEnd([System.IO.Path]::DirectorySeparatorChar, [System.IO.Path]::AltDirectorySeparatorChar) |
| | | $baseUri = New-Object System.Uri(($baseFullPath + [System.IO.Path]::DirectorySeparatorChar)) |
| | | $targetUri = New-Object System.Uri($targetFullPath) |
| | | $relativeUri = $baseUri.MakeRelativeUri($targetUri) |
| | | return [System.Uri]::UnescapeDataString($relativeUri.ToString()).Replace('/', [System.IO.Path]::DirectorySeparatorChar) |
| | | } |
| | | |
| | | function Backup-DeployedPluginConfigs { |
| | | param( |
| | | [Parameter(Mandatory = $true)] |
| | | [string]$ApplicationDirectory, |
| | | [Parameter(Mandatory = $true)] |
| | | [string]$BackupDirectory |
| | | ) |
| | | |
| | | $pluginsRoot = Join-Path $ApplicationDirectory "samples\plugins" |
| | | if (-not (Test-Path -LiteralPath $pluginsRoot)) { |
| | | return |
| | | } |
| | | |
| | | Get-ChildItem -LiteralPath $pluginsRoot -Directory | ForEach-Object { |
| | | $pluginJson = Join-Path $_.FullName "plugin.json" |
| | | if (-not (Test-Path -LiteralPath $pluginJson)) { |
| | | return |
| | | } |
| | | |
| | | $relativeDirectory = Get-RelativePathCompat -BasePath $pluginsRoot -TargetPath $_.FullName |
| | | $backupPluginDirectory = Join-Path $BackupDirectory $relativeDirectory |
| | | New-Item -ItemType Directory -Force -Path $backupPluginDirectory | Out-Null |
| | | Copy-Item -LiteralPath $pluginJson -Destination (Join-Path $backupPluginDirectory "plugin.json") -Force |
| | | } |
| | | } |
| | | |
| | | function Restore-DeployedPluginConfigs { |
| | | param( |
| | | [Parameter(Mandatory = $true)] |
| | | [string]$ApplicationDirectory, |
| | | [Parameter(Mandatory = $true)] |
| | | [string]$BackupDirectory |
| | | ) |
| | | |
| | | if (-not (Test-Path -LiteralPath $BackupDirectory)) { |
| | | return |
| | | } |
| | | |
| | | $pluginsRoot = Join-Path $ApplicationDirectory "samples\plugins" |
| | | Get-ChildItem -LiteralPath $BackupDirectory -Directory | ForEach-Object { |
| | | $relativeDirectory = Get-RelativePathCompat -BasePath $BackupDirectory -TargetPath $_.FullName |
| | | $targetPluginDirectory = Join-Path $pluginsRoot $relativeDirectory |
| | | $newPluginJson = Join-Path $targetPluginDirectory "plugin.json" |
| | | $templateJson = Join-Path $targetPluginDirectory "plugin.template.json" |
| | | $backupPluginJson = Join-Path $_.FullName "plugin.json" |
| | | |
| | | if ((Test-Path -LiteralPath $newPluginJson) -and -not (Test-Path -LiteralPath $templateJson)) { |
| | | Copy-Item -LiteralPath $newPluginJson -Destination $templateJson -Force |
| | | } |
| | | |
| | | if (Test-Path -LiteralPath $backupPluginJson) { |
| | | Copy-Item -LiteralPath $backupPluginJson -Destination $newPluginJson -Force |
| | | } |
| | | } |
| | | } |
| | | |
| | | $repoRoot = Resolve-Path (Join-Path $PSScriptRoot "..") |
| | | $solutionPath = Join-Path $repoRoot "Moli.Desktop.slnx" |
| | | $projectPath = Join-Path $repoRoot "src\Moli.Desktop\Moli.Desktop.csproj" |
| | | $stagingRoot = Join-Path $repoRoot "artifacts\release" |
| | | $publishDir = Join-Path $stagingRoot "publish\$AppName" |
| | | $configBackupDir = Join-Path $stagingRoot "preserved-plugin-configs" |
| | | $targetRootPath = Join-Path $TargetRoot "" |
| | | $targetDir = Join-Path $targetRootPath $AppName |
| | | $targetExePath = Join-Path $targetDir "$AppName.exe" |
| | |
| | | |
| | | Stop-PublishedApplication -ProcessName $AppName -ExecutablePath $targetExePath |
| | | |
| | | if (Test-Path -LiteralPath $configBackupDir) { |
| | | Remove-Item -LiteralPath $configBackupDir -Recurse -Force |
| | | } |
| | | New-Item -ItemType Directory -Force -Path $configBackupDir | Out-Null |
| | | Backup-DeployedPluginConfigs -ApplicationDirectory $targetDir -BackupDirectory $configBackupDir |
| | | |
| | | if (Test-Path -LiteralPath $targetDir) { |
| | | Write-Host "Removing old published files:" |
| | | Write-Host $targetDir |
| | |
| | | New-Item -ItemType Directory -Force -Path $targetDir | Out-Null |
| | | |
| | | Invoke-CheckedRobocopy -Source $publishDir -Destination $targetDir |
| | | Restore-DeployedPluginConfigs -ApplicationDirectory $targetDir -BackupDirectory $configBackupDir |
| | | |
| | | if (-not $NoZip) { |
| | | if (Test-Path -LiteralPath $zipPath) { |