Files
zyt/identity-admin/scripts/build-kefu-live-refresh.ps1
T
2026-11-11 13:53:14 +08:00

48 lines
3.3 KiB
PowerShell

$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $false
$identityRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
$snapshotRoot = Join-Path $identityRoot '.test-runtime/kefu-admin-web'
$mirrorRoot = Join-Path $identityRoot 'integration/kefu/admin-web'
$runtimeRoot = Join-Path $identityRoot '.test-runtime'
$protectedFiles = @('package.json', 'pnpm-lock.yaml', 'internal/tailwind-config/src/theme.css', 'apps/web-antd/node_modules/hash-wasm/package.json')
$frozen = @{}
foreach ($relative in $protectedFiles) {
$frozen[$relative] = (Get-FileHash -LiteralPath (Join-Path $snapshotRoot $relative)).Hash
}
if (@(Get-ChildItem -LiteralPath $snapshotRoot -Filter '.env*' -File).Count -or
@(Get-ChildItem -LiteralPath (Join-Path $snapshotRoot 'apps/web-antd') -Filter '.env*' -File).Count) {
throw 'Isolated build must not contain environment files'
}
$copied = @()
foreach ($file in Get-ChildItem -LiteralPath $mirrorRoot -Recurse -File) {
if ($file.Extension -notin @('.ts', '.vue', '.mjs', '.css')) { throw 'Unexpected non-public frontend source in mirror' }
$relative = [IO.Path]::GetRelativePath($mirrorRoot, $file.FullName)
$target = [IO.Path]::GetFullPath((Join-Path $snapshotRoot $relative))
if (-not $target.StartsWith($snapshotRoot + [IO.Path]::DirectorySeparatorChar, [StringComparison]::OrdinalIgnoreCase)) { throw 'Source path escaped isolated snapshot' }
New-Item -ItemType Directory -Path (Split-Path -Parent $target) -Force | Out-Null
Copy-Item -LiteralPath $file.FullName -Destination $target -Force
$copied += $relative
}
$env:VITE_ROUTER_HISTORY = 'history'
$env:VITE_APP_TITLE = '企微客服'
$env:VITE_GLOB_API_URL = '/api/v2'
$env:VITE_APP_NAMESPACE = 'kefu'
$env:VITE_BASE = '/'
Set-Location -LiteralPath $snapshotRoot
& pnpm.cmd --filter '@vben/web-antd' run typecheck *> (Join-Path $runtimeRoot 'kefu-live-refresh-typecheck.log')
$typeExit = $LASTEXITCODE
if ($typeExit -ne 0) { Get-Content (Join-Path $runtimeRoot 'kefu-live-refresh-typecheck.log') -Tail 45; exit $typeExit }
& pnpm.cmd --filter '@vben/web-antd' exec vite build --mode production --outDir dist-final *> (Join-Path $runtimeRoot 'kefu-live-refresh-build.log')
$buildExit = $LASTEXITCODE
if ($buildExit -ne 0) { Get-Content (Join-Path $runtimeRoot 'kefu-live-refresh-build.log') -Tail 45; exit $buildExit }
foreach ($relative in $protectedFiles) {
if ((Get-FileHash -LiteralPath (Join-Path $snapshotRoot $relative)).Hash -ne $frozen[$relative]) { throw "Frozen dependency changed: $relative" }
}
foreach ($relative in $copied) {
if ((Get-FileHash -LiteralPath (Join-Path $mirrorRoot $relative)).Hash -ne
(Get-FileHash -LiteralPath (Join-Path $snapshotRoot $relative)).Hash) { throw "Source changed during build: $relative" }
}
$result = @{typecheck_exit=$typeExit; build_exit=$buildExit; source_files=$copied; frozen_files_unchanged=$true; output=(Join-Path $snapshotRoot 'apps/web-antd/dist-final'); dependencies_installed=$false; deployed=$false; completed_at=(Get-Date).ToString('o')}
$result | ConvertTo-Json -Depth 4 | Set-Content -LiteralPath (Join-Path $runtimeRoot 'kefu-live-refresh-build-result.json') -Encoding utf8
Write-Output ('KF live-refresh typecheck/build passed; '+$copied.Count+' public files copied; frozen dependencies unchanged.')