sync-native-fast-printer.ps1 2.71 KB
$ErrorActionPreference = "Stop"

$appRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
$repoRoot = Split-Path -Parent (Split-Path -Parent $appRoot)
$dstPluginRoot = Join-Path $appRoot "nativeplugins\native-fast-printer"
$manifestPath = Join-Path $appRoot "src\manifest.json"

Write-Host "[1/4] Validate source plugin files..."
$preferredAar = Join-Path $repoRoot "打印机安卓基座\native-fast-printer\android\native_fast_printer-release.aar"
$sourceAarItem = $null
if (Test-Path -LiteralPath $preferredAar) {
  $sourceAarItem = Get-Item -LiteralPath $preferredAar
} else {
  $sourceAarItem = Get-ChildItem -LiteralPath (Join-Path $repoRoot "打印机安卓基座") -Recurse -File -Filter "native_fast_printer-release.aar" -ErrorAction SilentlyContinue |
    Sort-Object LastWriteTime -Descending |
    Select-Object -First 1
}
if ($null -eq $sourceAarItem) {
  throw "AAR not found. Build first: 打印机安卓基座/native-fast-printer/android-src/build-aar-windows.bat"
}

$srcPluginRoot = Split-Path -Parent (Split-Path -Parent $sourceAarItem.FullName)
$srcAar = $sourceAarItem.FullName
Write-Host "Selected SRC AAR: $srcAar"
$srcPkg = Join-Path $srcPluginRoot "package.json"
$srcReadme = Join-Path $srcPluginRoot "README.md"
if (!(Test-Path -LiteralPath $srcPkg)) { throw "package.json not found: $srcPkg" }
if (!(Test-Path -LiteralPath $srcReadme)) { throw "README.md not found: $srcReadme" }

Write-Host "[2/4] Sync files into uniapp nativeplugins..."
if (Test-Path -LiteralPath $dstPluginRoot) {
  Remove-Item -LiteralPath $dstPluginRoot -Recurse -Force
}
New-Item -ItemType Directory -Path (Join-Path $dstPluginRoot "android") -Force | Out-Null
Copy-Item -LiteralPath $srcPkg -Destination (Join-Path $dstPluginRoot "package.json")
Copy-Item -LiteralPath $srcReadme -Destination (Join-Path $dstPluginRoot "README.md")
Copy-Item -LiteralPath $srcAar -Destination (Join-Path $dstPluginRoot "android\native_fast_printer-release.aar")

Write-Host "[3/4] Validate manifest plugin declaration..."
if (!(Test-Path -LiteralPath $manifestPath)) { throw "manifest not found: $manifestPath" }
$manifestContent = Get-Content -LiteralPath $manifestPath -Raw
if ($manifestContent -notmatch '"native-fast-printer"\s*:\s*\{') {
  throw "manifest.json missing app-plus.nativePlugins.native-fast-printer declaration"
}

Write-Host "[4/4] Print summary..."
$srcInfo = Get-Item -LiteralPath $srcAar
$dstAar = Join-Path $dstPluginRoot "android\native_fast_printer-release.aar"
$dstInfo = Get-Item -LiteralPath $dstAar
Write-Host "SRC AAR: $($srcInfo.Length) bytes, $($srcInfo.LastWriteTime.ToString("s"))"
Write-Host "DST AAR: $($dstInfo.Length) bytes, $($dstInfo.LastWriteTime.ToString("s"))"
Write-Host "Done: native-fast-printer synced. Next: build custom base in HBuilderX."