# Zip chuan Linux/WordPress (duong dan trong zip dung /, KHONG dung \). # Chay: powershell -ExecutionPolicy Bypass -File tools/build-release.ps1 $ErrorActionPreference = 'Stop' $PluginDir = Split-Path -Parent $PSScriptRoot $MainPhp = Join-Path $PluginDir 'datvetaucaotoc-booking.php' if (-not (Test-Path $MainPhp)) { Write-Error "Khong tim thay: $MainPhp" } $versionLine = Select-String -Path $MainPhp -Pattern '^\s*\*\s*Version:\s*([0-9.]+)\s*$' | Select-Object -First 1 if (-not $versionLine) { Write-Error 'Khong doc duoc Version trong datvetaucaotoc-booking.php' } $Version = $versionLine.Matches.Groups[1].Value $WizardJs = Join-Path $PluginDir 'assets\build\wizard.js' if (-not (Test-Path $WizardJs)) { Write-Error "Thieu wizard.js — chay npm run build trong frontend/ truoc." } if ((Get-Item $WizardJs).Length -lt 1024) { Write-Error "wizard.js qua nho — build co the that bai." } function Write-CrossPlatformZip { param( [string]$SourceDir, [string]$DestinationPath, [string]$EntryPrefix = '' ) if (Test-Path $DestinationPath) { Remove-Item -LiteralPath $DestinationPath -Force } Add-Type -AssemblyName System.IO.Compression Add-Type -AssemblyName System.IO.Compression.FileSystem $sourceFull = (Resolve-Path $SourceDir).Path.TrimEnd('\') $prefix = $EntryPrefix if ($prefix -and -not $prefix.EndsWith('/')) { $prefix += '/' } $fs = [System.IO.File]::Create($DestinationPath) $zip = New-Object System.IO.Compression.ZipArchive($fs, [System.IO.Compression.ZipArchiveMode]::Create) try { Get-ChildItem -LiteralPath $sourceFull -Recurse -File | ForEach-Object { $rel = $_.FullName.Substring($sourceFull.Length + 1).Replace('\', '/') $entryName = $prefix + $rel $entry = $zip.CreateEntry($entryName, [System.IO.Compression.CompressionLevel]::Optimal) $inStream = [System.IO.File]::OpenRead($_.FullName) try { $outStream = $entry.Open() try { $inStream.CopyTo($outStream) } finally { $outStream.Dispose() } } finally { $inStream.Dispose() } } } finally { $zip.Dispose() $fs.Dispose() } } $StagingRoot = Join-Path $env:TEMP "datvetau-release-$Version" $StagingDir = Join-Path $StagingRoot 'datvetaucaotoc-booking' if (Test-Path $StagingRoot) { Remove-Item -LiteralPath $StagingRoot -Recurse -Force } New-Item -ItemType Directory -Path $StagingDir -Force | Out-Null $robocopyArgs = @( $PluginDir, $StagingDir, '/E', '/XD', 'node_modules', '.git', '/XF', 'datvetaucaotoc-booking.zip', 'datvetaucaotoc-booking-flat.zip', '/NFL', '/NDL', '/NJH', '/NJS', '/NC', '/NS' ) & robocopy @robocopyArgs | Out-Null if ($LASTEXITCODE -ge 8) { Write-Error "robocopy that bai (exit $LASTEXITCODE)" } $huongDan = @" CAI BANG WORDPRESS (Plugins -> Tai plugin len) =============================================== TRUOC KHI UPLOAD: - Plugins: Vo hieu hoa + Xoa het ban «Dat ve tau». - File Manager host: xoa wp-content/plugins/datvetaucaotoc-booking* UPLOAD file: datvetaucaotoc-booking.zip Sau khi cai dung, tren server KHONG duoc thay ten file co dau \ (backslash). Version: $Version "@ Set-Content -Path (Join-Path $StagingDir 'HUONG-DAN-CAI-DAT.txt') -Value $huongDan -Encoding UTF8 $zipPath = Join-Path $PluginDir 'datvetaucaotoc-booking.zip' $zipFlatLegacy = Join-Path $PluginDir 'datvetaucaotoc-booking-flat.zip' if (Test-Path $zipFlatLegacy) { Remove-Item -LiteralPath $zipFlatLegacy -Force } # Chuan WP: datvetaucaotoc-booking/includes/... (forward slash) Write-CrossPlatformZip -SourceDir $StagingDir -DestinationPath $zipPath -EntryPrefix 'datvetaucaotoc-booking' Remove-Item -LiteralPath $StagingRoot -Recurse -Force $sizeMb = [math]::Round((Get-Item $zipPath).Length / 1MB, 2) Write-Host "OK: $zipPath ($sizeMb MB) - version $Version" # Kiem tra khong con backslash trong ten entry Add-Type -AssemblyName System.IO.Compression.FileSystem $bad = [System.IO.Compression.ZipFile]::OpenRead($zipPath).Entries | Where-Object { $_.FullName -match '\\' } if ($bad) { Write-Error 'Zip van co backslash - loi build.' } Write-Host "Verified: zip entries use forward slashes only."