Files
WRNexusJS/APPLY_COMPONENT_SHOWCASE_UPDATE.ps1
T
2026-07-31 16:30:13 +05:30

110 lines
3.5 KiB
PowerShell

param(
[string]$Root = "E:\WireJS",
[switch]$SkipValidation
)
$ErrorActionPreference = "Stop"
$PackageRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
$Root = [System.IO.Path]::GetFullPath($Root)
if (-not (Test-Path (Join-Path $Root "packages\ui\components"))) {
throw "WRNexusJS repository was not found at: $Root"
}
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
$backupRoot = Join-Path $Root ".wrnexus\component-showcase-backup-$timestamp"
New-Item -ItemType Directory -Path $backupRoot -Force | Out-Null
$files = @(
"scripts/generate-ui-component-reference.mjs",
"packages/ui/component-catalog.json",
"examples/component-showcase/scripts/generate-showcase.mjs",
"examples/component-showcase/scripts/showcase-profiles.mjs",
"examples/component-showcase/public/playground.js",
"examples/component-showcase/app/styles/global.css",
"examples/component-showcase/test/showcase.test.ts",
"examples/component-showcase/README.md"
)
$generatedFiles = @(
"packages/ui/component-reference.json",
"packages/ui/COMPONENTS.md",
"examples/component-showcase/showcase-manifest.json"
)
function Convert-RelativePath([string]$relative) {
return $relative.Replace("/", [System.IO.Path]::DirectorySeparatorChar)
}
function Backup-Path([string]$relative) {
$platformPath = Convert-RelativePath $relative
$source = Join-Path $Root $platformPath
if (-not (Test-Path $source)) { return }
$destination = Join-Path $backupRoot $platformPath
$destinationParent = Split-Path -Parent $destination
New-Item -ItemType Directory -Path $destinationParent -Force | Out-Null
Copy-Item $source $destination -Recurse -Force
}
foreach ($relative in $files) { Backup-Path $relative }
foreach ($relative in $generatedFiles) { Backup-Path $relative }
Backup-Path "examples/component-showcase/app/pages"
Backup-Path "examples/component-showcase/app/layouts"
foreach ($relative in $files) {
$platformPath = Convert-RelativePath $relative
$source = Join-Path $PackageRoot $platformPath
$destination = Join-Path $Root $platformPath
if (-not (Test-Path $source)) {
throw "Patch file is missing: $source"
}
New-Item -ItemType Directory -Path (Split-Path -Parent $destination) -Force | Out-Null
Copy-Item $source $destination -Force
Write-Host "Updated $relative" -ForegroundColor Green
}
function Invoke-BunStep {
param(
[string]$Label,
[string[]]$Arguments
)
Write-Host "`n$Label" -ForegroundColor Cyan
& bun @Arguments
if ($LASTEXITCODE -ne 0) {
throw "$Label failed with exit code $LASTEXITCODE."
}
}
Push-Location $Root
try {
Invoke-BunStep "Generating the current UI component reference" @(
"run",
"scripts/generate-ui-component-reference.mjs"
)
$showcaseRoot = Join-Path $Root "examples\component-showcase"
Remove-Item (Join-Path $showcaseRoot ".wrnexus") -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item (Join-Path $showcaseRoot "dist") -Recurse -Force -ErrorAction SilentlyContinue
Push-Location $showcaseRoot
try {
Invoke-BunStep "Generating component showcase pages and manifest" @("run", "generate")
if (-not $SkipValidation) {
Invoke-BunStep "Validating the complete component showcase" @("run", "check")
}
}
finally {
Pop-Location
}
}
finally {
Pop-Location
}
Write-Host "`nComponent showcase update applied successfully." -ForegroundColor Green
Write-Host "Backup: $backupRoot"
if ($SkipValidation) {
Write-Host "Validation was skipped. Run: bun run --cwd examples/component-showcase check" -ForegroundColor Yellow
}