Skip to content

Commit 4deea4a

Browse files
committed
✨ [feat] Add cache-format upgrade workflow, manual validation override, and Show-ColorScript -ValidateCache
- ✨ Private/Ensure-CacheFormatVersion.ps1: add Set-CacheValidationOverride to let callers force cache validation; setting the override resets $script:CacheValidationPerformed so initialization will re-run validation. - ✨ Private/Ensure-CacheFormatVersion.ps1: extend Update-CacheFormatVersion to accept -MetadataFileName and write metadata using [int]$script:CacheFormatVersion (Version, ModuleVersion, UpdatedUtc). - ✨ Private/Ensure-CacheFormatVersion.ps1: implement purge of obsolete cache-metadata*.json files (remove files whose name != current MetadataFileName) with robust try/catch and Write-Verbose diagnostics to avoid breaking init on IO/parse failures. 🚜 [refactor] Integrate cache validation into initialization and add env override - 🚜 Private/Initialize-CacheDirectory.ps1: standardize metadata filename to 'cache-metadata-v{0}.json' and pass that name into Update-CacheFormatVersion. - 🚜 Private/Initialize-CacheDirectory.ps1: add support for COLOR_SCRIPTS_ENHANCED_VALIDATE_CACHE (accepts 1/true/yes) to force validation via environment. - 🚜 Private/Initialize-CacheDirectory.ps1: only run validation when forced (env), when manual override is set, or when validation hasn't been performed and the metadata file is missing; set $script:CacheValidationPerformed = $true after validation and clear the manual override. Apply same logic to the fallback resolution path. ✨ [feat] Public Show-ColorScript: add -ValidateCache switch - ✨ Public/Show-ColorScript.ps1: add .PARAMETER ValidateCache documentation and new [switch]$ValidateCache parameter. - ✨ Public/Show-ColorScript.ps1: when -ValidateCache is supplied call Set-CacheValidationOverride -Value $true so callers can force cache rebuild/validation before rendering. 🔧 [build] Bump module version and release notes header - 🔧 ColorScripts-Enhanced/ColorScripts-Enhanced.psd1: bump ModuleVersion => '2025.11.05.2125' and update embedded ReleaseNotes header to match the new stamp. 📝 [docs] Sync localized help UICultureVersion stamps - 📝 Update localized HelpInfo.xml files (en-US, de, es, fr, it, ja, nl, pt, ru, zh-CN) to the new UICultureVersion stamp to keep manifest/help metadata consistent with the module bump. 🧪 [test] Initialize cache-validation state in tests - 🧪 Tests/*: reset $script:CacheValidationPerformed = $false and $script:CacheValidationManualOverride = $false in test setup fixtures (CoverageExpansion, InternalCoverage, TargetedCoverage) so tests run with deterministic cache-validation state. 📝 [docs] Regenerate packaged release artifacts - 📝 dist/LatestReleaseNotes.md & dist/PowerShellGalleryReleaseNotes.md: regenerate release notes header/content to reflect the cache-format workflow, validation changes and module/help version bumps. Signed-off-by: Nick2bad4u <20943337+Nick2bad4u@users.noreply.github.com>
1 parent e25ac30 commit 4deea4a

19 files changed

Lines changed: 514 additions & 39 deletions

ColorScripts-Enhanced/ColorScripts-Enhanced.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
RootModule = 'ColorScripts-Enhanced.psm1'
1212

1313
# Version number of this module.
14-
ModuleVersion = '2025.11.05.1912'
14+
ModuleVersion = '2025.11.05.2125'
1515

1616
# Supported PSEditions
1717
CompatiblePSEditions = @('Desktop', 'Core')
@@ -211,7 +211,7 @@ PERFECT FOR
211211

212212
# ReleaseNotes of this module
213213
ReleaseNotes = @'
214-
Version 2025.11.05.1912:
214+
Version 2025.11.05.2125:
215215
- Enhanced caching system with OS-wide cache in AppData
216216
- 6-19x performance improvement
217217
- Cache stored in centralized location

ColorScripts-Enhanced/Private/Ensure-CacheFormatVersion.ps1

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,58 @@ if (-not $script:CacheFormatVersion) {
22
$script:CacheFormatVersion = 2
33
}
44

5+
if ($null -eq $script:CacheValidationManualOverride) {
6+
$script:CacheValidationManualOverride = $false
7+
}
8+
9+
if ($null -eq $script:CacheValidationPerformed) {
10+
$script:CacheValidationPerformed = $false
11+
}
12+
13+
function Set-CacheValidationOverride {
14+
param(
15+
[Parameter(Mandatory)]
16+
[bool]$Value
17+
)
18+
19+
$script:CacheValidationManualOverride = $Value
20+
21+
if ($Value) {
22+
$script:CacheValidationPerformed = $false
23+
}
24+
}
25+
526
function Update-CacheFormatVersion {
627
param(
728
[Parameter(Mandatory)]
829
[ValidateNotNullOrEmpty()]
9-
[string]$CacheDirectory
30+
[string]$CacheDirectory,
31+
32+
[Parameter(Mandatory)]
33+
[ValidateNotNullOrEmpty()]
34+
[string]$MetadataFileName
1035
)
1136

1237
if (-not (Test-Path -LiteralPath $CacheDirectory -PathType Container)) {
1338
return
1439
}
1540

16-
$metadataPath = Join-Path -Path $CacheDirectory -ChildPath 'cache-metadata.json'
17-
$currentVersion = $null
41+
$metadataPath = Join-Path -Path $CacheDirectory -ChildPath $MetadataFileName
1842

19-
if (Test-Path -LiteralPath $metadataPath -PathType Leaf) {
20-
try {
21-
$metadataJson = Get-Content -LiteralPath $metadataPath -Raw
22-
if ($metadataJson) {
23-
$metadata = ConvertFrom-Json -InputObject $metadataJson -ErrorAction Stop
24-
if ($metadata -and $metadata.PSObject.Properties.Match('Version')) {
25-
$currentVersion = [int]$metadata.Version
43+
try {
44+
Get-ChildItem -LiteralPath $CacheDirectory -Filter 'cache-metadata*.json' -File -ErrorAction Stop |
45+
Where-Object { $_.Name -ne $MetadataFileName } |
46+
ForEach-Object {
47+
try {
48+
Remove-Item -LiteralPath $_.FullName -Force -ErrorAction Stop
49+
}
50+
catch {
51+
Write-Verbose ("Failed to remove obsolete cache metadata '{0}': {1}" -f $_.FullName, $_.Exception.Message)
52+
}
2653
}
27-
}
28-
}
29-
catch {
30-
Write-Verbose ("Cache metadata read failed: {0}" -f $_.Exception.Message)
31-
$currentVersion = $null
32-
}
3354
}
34-
35-
$targetVersion = [int]$script:CacheFormatVersion
36-
if ($currentVersion -eq $targetVersion) {
37-
return
55+
catch {
56+
Write-Verbose ("Cache metadata cleanup failed: {0}" -f $_.Exception.Message)
3857
}
3958

4059
try {
@@ -62,7 +81,7 @@ function Update-CacheFormatVersion {
6281
}
6382

6483
$metadataObject = [pscustomobject]@{
65-
Version = $targetVersion
84+
Version = [int]$script:CacheFormatVersion
6685
ModuleVersion = $moduleVersion
6786
UpdatedUtc = (Get-Date).ToUniversalTime().ToString('o')
6887
}

ColorScripts-Enhanced/Private/Initialize-CacheDirectory.ps1

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,34 @@ function Initialize-CacheDirectory {
7171

7272
$resolvedCacheDir = Resolve-PreferredDirectoryCandidate -CandidatePaths $candidatePaths -OnCreateFailure $onCreateFailure -OnResolutionFailure $onResolutionFailure
7373

74+
$metadataFileName = 'cache-metadata-v{0}.json' -f $script:CacheFormatVersion
75+
$envValidateValue = $env:COLOR_SCRIPTS_ENHANCED_VALIDATE_CACHE
76+
$forceViaEnv = $false
77+
if ($envValidateValue -and $envValidateValue -match '^(1|true|yes)$') {
78+
$forceViaEnv = $true
79+
}
80+
7481
if ($resolvedCacheDir) {
7582
$script:CacheDir = $resolvedCacheDir
7683
$script:CacheInitialized = $true
77-
Update-CacheFormatVersion -CacheDirectory $script:CacheDir
84+
85+
$shouldValidate = $false
86+
if ($forceViaEnv -or $script:CacheValidationManualOverride) {
87+
$shouldValidate = $true
88+
}
89+
elseif (-not $script:CacheValidationPerformed) {
90+
$metadataPath = Join-Path -Path $script:CacheDir -ChildPath $metadataFileName
91+
if (-not (Test-Path -LiteralPath $metadataPath -PathType Leaf)) {
92+
$shouldValidate = $true
93+
}
94+
}
95+
96+
if ($shouldValidate) {
97+
Update-CacheFormatVersion -CacheDirectory $script:CacheDir -MetadataFileName $metadataFileName
98+
$script:CacheValidationPerformed = $true
99+
}
100+
101+
$script:CacheValidationManualOverride = $false
78102
return
79103
}
80104

@@ -99,6 +123,23 @@ function Initialize-CacheDirectory {
99123

100124
$script:CacheDir = $resolvedFallback
101125
$script:CacheInitialized = $true
102-
Update-CacheFormatVersion -CacheDirectory $script:CacheDir
126+
127+
$shouldValidateFallback = $false
128+
if ($forceViaEnv -or $script:CacheValidationManualOverride) {
129+
$shouldValidateFallback = $true
130+
}
131+
elseif (-not $script:CacheValidationPerformed) {
132+
$metadataPath = Join-Path -Path $script:CacheDir -ChildPath $metadataFileName
133+
if (-not (Test-Path -LiteralPath $metadataPath -PathType Leaf)) {
134+
$shouldValidateFallback = $true
135+
}
136+
}
137+
138+
if ($shouldValidateFallback) {
139+
Update-CacheFormatVersion -CacheDirectory $script:CacheDir -MetadataFileName $metadataFileName
140+
$script:CacheValidationPerformed = $true
141+
}
142+
143+
$script:CacheValidationManualOverride = $false
103144
}
104145
}

ColorScripts-Enhanced/Public/Show-ColorScript.ps1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ function Show-ColorScript {
4848
.PARAMETER NoAnsiOutput
4949
Disable ANSI color codes in informational messages and rendered script text for plain-text environments.
5050
51+
.PARAMETER ValidateCache
52+
Forces cache validation before rendering. Use when you need to rebuild cached colorscript output manually.
53+
5154
.EXAMPLE
5255
Show-ColorScript
5356
Displays a random colorscript.
@@ -261,14 +264,21 @@ function Show-ColorScript {
261264

262265
[Parameter()]
263266
[Alias('NoColor')]
264-
[switch]$NoAnsiOutput
267+
[switch]$NoAnsiOutput,
268+
269+
[Parameter()]
270+
[switch]$ValidateCache
265271
)
266272

267273
if ($h) {
268274
Show-ColorScriptHelp -CommandName 'Show-ColorScript'
269275
return
270276
}
271277

278+
if ($ValidateCache) {
279+
Set-CacheValidationOverride -Value $true
280+
}
281+
272282
$quietRequested = $Quiet.IsPresent
273283
$noAnsiRequested = $NoAnsiOutput.IsPresent
274284

@@ -483,4 +493,3 @@ function Show-ColorScript {
483493
return $selection
484494
}
485495
}
486-

ColorScripts-Enhanced/de/ColorScripts-Enhanced_f77548d7-23eb-48ce-a6e0-f64b4758d995_HelpInfo.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<SupportedUICultures>
55
<UICulture>
66
<UICultureName>de</UICultureName>
7-
<UICultureVersion>2025.11.05.1912</UICultureVersion>
7+
<UICultureVersion>2025.11.05.2125</UICultureVersion>
88
</UICulture>
99
</SupportedUICultures>
1010
</HelpInfo>

ColorScripts-Enhanced/en-US/ColorScripts-Enhanced_f77548d7-23eb-48ce-a6e0-f64b4758d995_HelpInfo.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<SupportedUICultures>
55
<UICulture>
66
<UICultureName>en-US</UICultureName>
7-
<UICultureVersion>2025.11.05.1912</UICultureVersion>
7+
<UICultureVersion>2025.11.05.2125</UICultureVersion>
88
</UICulture>
99
</SupportedUICultures>
1010
</HelpInfo>

ColorScripts-Enhanced/es/ColorScripts-Enhanced_f77548d7-23eb-48ce-a6e0-f64b4758d995_HelpInfo.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<SupportedUICultures>
55
<UICulture>
66
<UICultureName>es</UICultureName>
7-
<UICultureVersion>2025.11.05.1912</UICultureVersion>
7+
<UICultureVersion>2025.11.05.2125</UICultureVersion>
88
</UICulture>
99
</SupportedUICultures>
1010
</HelpInfo>

ColorScripts-Enhanced/fr/ColorScripts-Enhanced_f77548d7-23eb-48ce-a6e0-f64b4758d995_HelpInfo.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<SupportedUICultures>
55
<UICulture>
66
<UICultureName>fr</UICultureName>
7-
<UICultureVersion>2025.11.05.1912</UICultureVersion>
7+
<UICultureVersion>2025.11.05.2125</UICultureVersion>
88
</UICulture>
99
</SupportedUICultures>
1010
</HelpInfo>

ColorScripts-Enhanced/it/ColorScripts-Enhanced_f77548d7-23eb-48ce-a6e0-f64b4758d995_HelpInfo.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<SupportedUICultures>
55
<UICulture>
66
<UICultureName>it</UICultureName>
7-
<UICultureVersion>2025.11.05.1912</UICultureVersion>
7+
<UICultureVersion>2025.11.05.2125</UICultureVersion>
88
</UICulture>
99
</SupportedUICultures>
1010
</HelpInfo>

ColorScripts-Enhanced/ja/ColorScripts-Enhanced_f77548d7-23eb-48ce-a6e0-f64b4758d995_HelpInfo.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<SupportedUICultures>
55
<UICulture>
66
<UICultureName>ja</UICultureName>
7-
<UICultureVersion>2025.11.05.1912</UICultureVersion>
7+
<UICultureVersion>2025.11.05.2125</UICultureVersion>
88
</UICulture>
99
</SupportedUICultures>
1010
</HelpInfo>

0 commit comments

Comments
 (0)