cont develop configloader

This commit is contained in:
2025-11-10 10:16:23 -07:00
parent e541aa1a12
commit db2ee821fb
7 changed files with 9572 additions and 114 deletions

File diff suppressed because one or more lines are too long

View File

@@ -15,8 +15,8 @@ root (copied alongside helper batches when they are deployed to projects).
## Notes ## Notes
- `UpgradeSeqBatches.ps1` copies `config.json` and `ConfigLoader.ps1` to every - `UpdateProjectBatches.ps1` copies `config.json` and `ConfigLoader.ps1` to the
target folder so the helper `.bat` launchers can resolve script locations. target project so the helper `.bat` launchers can resolve script locations.
- When `zipper` is `true`, the tool searches for `7z`/`7za` on `PATH`. If neither - When `zipper` is `true`, the tool searches for `7z`/`7za` on `PATH`. If neither
is found it logs a warning and falls back to `zipfile`. is found it logs a warning and falls back to `zipfile`.
- Leaving `structDir` empty is safe—the scripts fall back to the directory that - Leaving `structDir` empty is safe—the scripts fall back to the directory that

View File

@@ -9,13 +9,13 @@ set "CONFIG_PATH=%REN_DIR%config.json"
if not exist "%CONFIG_LOADER%" ( if not exist "%CONFIG_LOADER%" (
echo [ERROR] ConfigLoader.ps1 not found next to UnzipSeqArchv.bat. echo [ERROR] ConfigLoader.ps1 not found next to UnzipSeqArchv.bat.
echo Please run UpgradeSeqBatches.ps1 to refresh helper files. echo Please run UpdateProjectBatches.ps1 to refresh helper files.
exit /b 1 exit /b 1
) )
if not exist "%CONFIG_PATH%" ( if not exist "%CONFIG_PATH%" (
echo [ERROR] config.json not found next to UnzipSeqArchv.bat. echo [ERROR] config.json not found next to UnzipSeqArchv.bat.
echo Please run UpgradeSeqBatches.ps1 to refresh helper files. echo Please run UpdateProjectBatches.ps1 to refresh helper files.
exit /b 1 exit /b 1
) )

147
UpdateProjectBatches.ps1 Normal file
View File

@@ -0,0 +1,147 @@
# Refresh helper batch scripts within a specific project directory.
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
param(
[string]$ProjectPath
)
if (-not $PSScriptRoot) {
$PSScriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
}
$configLoader = Join-Path -Path $PSScriptRoot -ChildPath 'ConfigLoader.ps1'
if (-not (Test-Path -LiteralPath $configLoader)) {
throw "Missing ConfigLoader.ps1 in $PSScriptRoot"
}
. $configLoader
$structDir = Get-StructDirectory
if (-not (Test-Path -LiteralPath $structDir -PathType Container)) {
throw "Configured structDir not found: $structDir"
}
if ([string]::IsNullOrWhiteSpace($ProjectPath)) {
$ProjectPath = Read-Host 'Enter the full path to the project directory'
}
if ([string]::IsNullOrWhiteSpace($ProjectPath)) {
Write-Error 'No project directory provided.'
exit 1
}
try {
$resolvedProject = (Resolve-Path -LiteralPath $ProjectPath -ErrorAction Stop).Path
}
catch {
Write-Error "Unable to resolve project directory: $($_.Exception.Message)"
exit 1
}
if (-not (Test-Path -LiteralPath $resolvedProject -PathType Container)) {
Write-Error "Project path is not a directory: $resolvedProject"
exit 1
}
Write-Host "Project directory: $resolvedProject" -ForegroundColor Cyan
Write-Host "Struct directory: $structDir" -ForegroundColor Cyan
$specs = @(
@{ Name = 'UpdateSequences.bat'; Source = Join-Path -Path $structDir -ChildPath 'UpdateSequences.bat' },
@{ Name = 'UpdateAllSequences.bat'; Source = Join-Path -Path $structDir -ChildPath 'UpdateAllSequences.bat' },
@{ Name = 'ZipSeqArchv.bat'; Source = Join-Path -Path $structDir -ChildPath 'ZipSeqArchv.bat' },
@{ Name = 'UnzipSeqArchv.bat'; Source = Join-Path -Path $structDir -ChildPath 'UnzipSeqArchv.bat' },
@{ Name = 'NewDaily.bat'; Source = Join-Path -Path $structDir -ChildPath 'NewDaily.bat' }
)
$sharedAssets = @(
@{ Name = 'ConfigLoader.ps1'; Source = Join-Path -Path $structDir -ChildPath 'ConfigLoader.ps1' },
@{ Name = 'config.json'; Source = Join-Path -Path $structDir -ChildPath 'config.json' }
)
foreach ($spec in $specs) {
if (-not (Test-Path -LiteralPath $spec.Source -PathType Leaf)) {
Write-Error "Source file not found: $($spec.Source)"
exit 1
}
}
foreach ($asset in $sharedAssets) {
if (-not (Test-Path -LiteralPath $asset.Source -PathType Leaf)) {
Write-Error "Shared asset not found: $($asset.Source)"
exit 1
}
}
$touchedDirs = @{}
$summary = @()
foreach ($spec in $specs) {
Write-Host "`n=== Updating $($spec.Name) ===" -ForegroundColor Magenta
$targets = Get-ChildItem -LiteralPath $resolvedProject -Recurse -Filter $spec.Name -File -ErrorAction SilentlyContinue
$targets = $targets | Where-Object { $_.FullName -ne $spec.Source }
if (-not $targets) {
Write-Host "No targets found." -ForegroundColor Yellow
$summary += [pscustomobject]@{
Name = $spec.Name
Updated = 0
Failed = 0
Skipped = 0
Total = 0
}
continue
}
$updated = 0
$failed = 0
foreach ($target in $targets) {
try {
Copy-Item -Path $spec.Source -Destination $target.FullName -Force
Write-Host "$($target.FullName)" -ForegroundColor Green
$updated++
$targetDir = $target.Directory.FullName
if (-not $touchedDirs.ContainsKey($targetDir)) {
foreach ($asset in $sharedAssets) {
try {
Copy-Item -Path $asset.Source -Destination (Join-Path -Path $targetDir -ChildPath $asset.Name) -Force
}
catch {
Write-Host " ✗ Failed to copy $($asset.Name) into $targetDir: $($_.Exception.Message)" -ForegroundColor Red
}
}
$touchedDirs[$targetDir] = $true
}
}
catch {
Write-Host "$($target.FullName)" -ForegroundColor Red
Write-Host " $($_.Exception.Message)" -ForegroundColor DarkRed
$failed++
}
}
$summary += [pscustomobject]@{
Name = $spec.Name
Updated = $updated
Failed = $failed
Skipped = 0
Total = $targets.Count
}
}
Write-Host "`n=== Summary ===" -ForegroundColor Cyan
foreach ($item in $summary) {
Write-Host ("{0,-22} Updated: {1,3} Failed: {2,3} Total: {3,3}" -f $item.Name, $item.Updated, $item.Failed, $item.Total)
}
if (($summary | Measure-Object -Property Failed -Sum).Sum -gt 0) {
Write-Host "Completed with errors." -ForegroundColor Yellow
exit 1
}
Write-Host "All batch files refreshed successfully." -ForegroundColor Green

View File

@@ -7,13 +7,13 @@ set "config_path=%script_dir%config.json"
if not exist "%config_loader%" ( if not exist "%config_loader%" (
echo [ERROR] ConfigLoader.ps1 not found next to UpdateSequences.bat. echo [ERROR] ConfigLoader.ps1 not found next to UpdateSequences.bat.
echo Please run UpgradeSeqBatches.ps1 to refresh helper files. echo Please run UpdateProjectBatches.ps1 to refresh helper files.
exit /b 1 exit /b 1
) )
if not exist "%config_path%" ( if not exist "%config_path%" (
echo [ERROR] config.json not found next to UpdateSequences.bat. echo [ERROR] config.json not found next to UpdateSequences.bat.
echo Please run UpgradeSeqBatches.ps1 to refresh helper files. echo Please run UpdateProjectBatches.ps1 to refresh helper files.
exit /b 1 exit /b 1
) )

View File

@@ -1,110 +1,8 @@
# Update subfolders with the latest UpdateSequences and UpdateAllSequences scripts # Deprecated helper retained for compatibility.
Set-StrictMode -Version Latest Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop' $ErrorActionPreference = 'Stop'
if (-not $PSScriptRoot) { Write-Warning 'UpgradeSeqBatches.ps1 has been deprecated.'
$PSScriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path Write-Warning 'Please run UpdateProjectBatches.ps1 and choose the project that needs refreshed batch files.'
} exit 1
$configLoader = Join-Path -Path $PSScriptRoot -ChildPath 'ConfigLoader.ps1'
if (-not (Test-Path -LiteralPath $configLoader)) {
throw "Missing ConfigLoader.ps1 in $PSScriptRoot"
}
. $configLoader
$structDir = Get-StructDirectory
$projectsRoot = Get-ProjectsRoot
$sourceBat = Join-Path -Path $structDir -ChildPath 'UpdateSequences.bat'
$sourceAllBat = Join-Path -Path $structDir -ChildPath 'UpdateAllSequences.bat'
$sourceZipBat = Join-Path -Path $structDir -ChildPath 'ZipSeqArchv.bat'
$sourceUnzipBat = Join-Path -Path $structDir -ChildPath 'UnzipSeqArchv.bat'
$configLoaderSource = Join-Path -Path $structDir -ChildPath 'ConfigLoader.ps1'
$configJsonSource = Join-Path -Path $structDir -ChildPath 'config.json'
if (-not (Test-Path -LiteralPath $sourceBat)) { Write-Error "Source file not found: $sourceBat"; exit 1 }
if (-not (Test-Path -LiteralPath $sourceAllBat)) { Write-Error "Source file not found: $sourceAllBat"; exit 1 }
if (-not (Test-Path -LiteralPath $sourceZipBat)) { Write-Error "Source file not found: $sourceZipBat"; exit 1 }
if (-not (Test-Path -LiteralPath $sourceUnzipBat)) { Write-Error "Source file not found: $sourceUnzipBat"; exit 1 }
if (-not (Test-Path -LiteralPath $configLoaderSource)) { Write-Error "Config loader not found: $configLoaderSource"; exit 1 }
if (-not (Test-Path -LiteralPath $configJsonSource)) { Write-Error "Config file not found: $configJsonSource"; exit 1 }
$specs = @(
@{ Name = "UpdateSequences.bat"; Source = $sourceBat },
@{ Name = "UpdateAllSequences.bat"; Source = $sourceAllBat },
@{ Name = "ZipSeqArchv.bat"; Source = $sourceZipBat },
@{ Name = "UnzipSeqArchv.bat"; Source = $sourceUnzipBat }
)
$sharedAssets = @(
@{ Name = 'ConfigLoader.ps1'; Source = $configLoaderSource },
@{ Name = 'config.json'; Source = $configJsonSource }
)
$grandTotal = 0
$grandUpdated = 0
$grandFailed = 0
$touchedDirs = @{}
foreach ($spec in $specs) {
Write-Host "=== Updating $($spec.Name) files ===" -ForegroundColor Cyan
Write-Host "Source: $($spec.Source)" -ForegroundColor White
Write-Host ""
$targets = Get-ChildItem -LiteralPath $projectsRoot -Recurse -Filter $spec.Name -File -ErrorAction SilentlyContinue |
Where-Object { $_.FullName -ne $spec.Source }
Write-Host "Found $($targets.Count) target files to update:" -ForegroundColor Yellow
foreach ($t in $targets) { Write-Host " - $($t.FullName)" -ForegroundColor Gray }
Write-Host ""
$updated = 0
$failed = 0
foreach ($t in $targets) {
$targetDir = $t.Directory.FullName
try {
Copy-Item -Path $spec.Source -Destination $t.FullName -Force
Write-Host "✓ Updated: $($t.FullName)" -ForegroundColor Green
$updated++
if (-not $touchedDirs.ContainsKey($targetDir)) {
foreach ($asset in $sharedAssets) {
try {
Copy-Item -Path $asset.Source -Destination (Join-Path -Path $targetDir -ChildPath $asset.Name) -Force
}
catch {
Write-Host "✗ Failed to copy $($asset.Name) to $targetDir" -ForegroundColor Red
Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red
}
}
$touchedDirs[$targetDir] = $true
}
}
catch {
Write-Host "✗ Failed to update: $($t.FullName)" -ForegroundColor Red
Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red
$failed++
}
}
Write-Host ""
Write-Host "=== $($spec.Name) SUMMARY ===" -ForegroundColor Magenta
Write-Host "Successfully updated: $updated" -ForegroundColor Green
Write-Host "Failed updates: $failed" -ForegroundColor Red
Write-Host "Total targets: $($targets.Count)" -ForegroundColor White
Write-Host ""
$grandTotal += $targets.Count
$grandUpdated += $updated
$grandFailed += $failed
}
Write-Host "=== OVERALL SUMMARY ===" -ForegroundColor Magenta
Write-Host "Total targets across all files: $grandTotal" -ForegroundColor White
Write-Host "Total successfully updated: $grandUpdated" -ForegroundColor Green
Write-Host "Total failed: $grandFailed" -ForegroundColor Red
if ($grandFailed -eq 0) {
Write-Host "`n🎉 All files updated successfully!" -ForegroundColor Green
} else {
Write-Host "`n⚠️ Some updates failed. See errors above." -ForegroundColor Yellow
}

View File

@@ -9,13 +9,13 @@ set "CONFIG_PATH=%REN_DIR%config.json"
if not exist "%CONFIG_LOADER%" ( if not exist "%CONFIG_LOADER%" (
echo [ERROR] ConfigLoader.ps1 not found next to ZipSeqArchv.bat. echo [ERROR] ConfigLoader.ps1 not found next to ZipSeqArchv.bat.
echo Please run UpgradeSeqBatches.ps1 to refresh helper files. echo Please run UpdateProjectBatches.ps1 to refresh helper files.
exit /b 1 exit /b 1
) )
if not exist "%CONFIG_PATH%" ( if not exist "%CONFIG_PATH%" (
echo [ERROR] config.json not found next to ZipSeqArchv.bat. echo [ERROR] config.json not found next to ZipSeqArchv.bat.
echo Please run UpgradeSeqBatches.ps1 to refresh helper files. echo Please run UpdateProjectBatches.ps1 to refresh helper files.
exit /b 1 exit /b 1
) )