Skip to content

Commit e25ac30

Browse files
committed
🛠️ [fix] Add cache-format upgrade workflow, unify colorscript execution, and bump module/help versions
✨ [feat] Add Ensure-CacheFormatVersion.ps1 - 🧩 Implements Update-CacheFormatVersion to manage cache-metadata.json (Version, ModuleVersion, UpdatedUtc) and purge existing *.cache files when the format version changes. - ⚠️ Includes robust error handling and Write-Verbose diagnostics to avoid breaking initialization on IO/parse failures. 🚜 [refactor] Integrate cache-format upgrade into initialization - 🔁 Call Update-CacheFormatVersion from Initialize-CacheDirectory immediately after resolving/creating the cache directory (both primary resolution and fallback) so caches are validated/upgraded and stale .cache files are removed automatically. 🚜 [refactor] Unify colorscript execution to isolated process - 🖥️ Remove the fast in-process execution path and always spawn an isolated PowerShell process to preserve ANSI sequences and console rendering fidelity. - 🧭 When running for cache builds (ForCache), set child env var COLOR_SCRIPTS_ENHANCED_CACHE_BUILD='1' so the subprocess can detect cache-build context; fail-safe verbose handling if env cannot be written. 🔧 [build] Bump ModuleVersion and update ReleaseNotes - 🔢 Update ModuleVersion to '2025.11.05.1912' in the module manifest and adjust the ReleaseNotes header to the new stamp. 📝 [docs] Sync localized HelpInfo UICultureVersion stamps - 🌐 Update SupportedUICultures / UICultureVersion for localized HelpInfo.xml files (en-US, de, es, fr, it, ja, nl, pt, ru, zh-CN) to match the new module stamp. 🧪 [test] Update tests to initialize cache directory and pass explicit cache path - 🔎 Tests now call Initialize-CacheDirectory inside module scope to retrieve $script:CacheDir and pass the explicit testCachePath into test blocks, ensuring tests operate on the real cache location and not an assumed variable. Signed-off-by: Nick2bad4u <20943337+Nick2bad4u@users.noreply.github.com>
1 parent 35c5457 commit e25ac30

15 files changed

Lines changed: 113 additions & 51 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.1634'
14+
ModuleVersion = '2025.11.05.1912'
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.1634:
214+
Version 2025.11.05.1912:
215215
- Enhanced caching system with OS-wide cache in AppData
216216
- 6-19x performance improvement
217217
- Cache stored in centralized location
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
if (-not $script:CacheFormatVersion) {
2+
$script:CacheFormatVersion = 2
3+
}
4+
5+
function Update-CacheFormatVersion {
6+
param(
7+
[Parameter(Mandatory)]
8+
[ValidateNotNullOrEmpty()]
9+
[string]$CacheDirectory
10+
)
11+
12+
if (-not (Test-Path -LiteralPath $CacheDirectory -PathType Container)) {
13+
return
14+
}
15+
16+
$metadataPath = Join-Path -Path $CacheDirectory -ChildPath 'cache-metadata.json'
17+
$currentVersion = $null
18+
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
26+
}
27+
}
28+
}
29+
catch {
30+
Write-Verbose ("Cache metadata read failed: {0}" -f $_.Exception.Message)
31+
$currentVersion = $null
32+
}
33+
}
34+
35+
$targetVersion = [int]$script:CacheFormatVersion
36+
if ($currentVersion -eq $targetVersion) {
37+
return
38+
}
39+
40+
try {
41+
Get-ChildItem -LiteralPath $CacheDirectory -Filter '*.cache' -File -ErrorAction Stop | ForEach-Object {
42+
try {
43+
Remove-Item -LiteralPath $_.FullName -Force -ErrorAction Stop
44+
}
45+
catch {
46+
Write-Verbose ("Failed to remove cache file '{0}': {1}" -f $_.FullName, $_.Exception.Message)
47+
}
48+
}
49+
}
50+
catch {
51+
Write-Verbose ("Cache purge enumeration failed: {0}" -f $_.Exception.Message)
52+
}
53+
54+
$moduleVersion = $null
55+
try {
56+
if ($ExecutionContext.SessionState -and $ExecutionContext.SessionState.Module) {
57+
$moduleVersion = $ExecutionContext.SessionState.Module.Version.ToString()
58+
}
59+
}
60+
catch {
61+
$moduleVersion = $null
62+
}
63+
64+
$metadataObject = [pscustomobject]@{
65+
Version = $targetVersion
66+
ModuleVersion = $moduleVersion
67+
UpdatedUtc = (Get-Date).ToUniversalTime().ToString('o')
68+
}
69+
70+
$metadataJson = $metadataObject | ConvertTo-Json -Depth 3
71+
$encoding = New-Object System.Text.UTF8Encoding($false)
72+
73+
try {
74+
[System.IO.File]::WriteAllText($metadataPath, $metadataJson, $encoding)
75+
}
76+
catch {
77+
Write-Verbose ("Cache metadata write failed: {0}" -f $_.Exception.Message)
78+
}
79+
}

ColorScripts-Enhanced/Private/Initialize-CacheDirectory.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ function Initialize-CacheDirectory {
7474
if ($resolvedCacheDir) {
7575
$script:CacheDir = $resolvedCacheDir
7676
$script:CacheInitialized = $true
77+
Update-CacheFormatVersion -CacheDirectory $script:CacheDir
7778
return
7879
}
7980

@@ -98,5 +99,6 @@ function Initialize-CacheDirectory {
9899

99100
$script:CacheDir = $resolvedFallback
100101
$script:CacheInitialized = $true
102+
Update-CacheFormatVersion -CacheDirectory $script:CacheDir
101103
}
102104
}

ColorScripts-Enhanced/Private/Invoke-ColorScriptProcess.ps1

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
function Invoke-ColorScriptProcess {
22
<#
33
.SYNOPSIS
4-
Executes a colorscript and captures its output.
5-
For cache building, uses fast in-process execution.
6-
For display, can use isolated process if needed.
4+
Executes a colorscript and captures its output using an isolated process
5+
to preserve ANSI sequences and console rendering fidelity.
76
#>
87
[CmdletBinding()]
98
param(
@@ -28,39 +27,6 @@ function Invoke-ColorScriptProcess {
2827
return $result
2928
}
3029

31-
# Fast in-process execution for cache building
32-
if ($ForCache) {
33-
try {
34-
$oldLocation = Get-Location -PSProvider FileSystem
35-
$scriptDirectory = [System.IO.Path]::GetDirectoryName($ScriptPath)
36-
if ($scriptDirectory) {
37-
Set-Location -LiteralPath $scriptDirectory -ErrorAction SilentlyContinue
38-
}
39-
40-
$scriptContent = & $script:FileReadAllTextDelegate $ScriptPath $script:Utf8NoBomEncoding
41-
$scriptBlock = [ScriptBlock]::Create($scriptContent)
42-
43-
$output = & $scriptBlock *>&1 | Out-String
44-
45-
$result.StdOut = $output
46-
$result.ExitCode = 0
47-
$result.Success = $true
48-
}
49-
catch {
50-
$result.StdErr = $_.Exception.Message
51-
$result.ExitCode = 1
52-
$result.Success = $false
53-
}
54-
finally {
55-
if ($oldLocation) {
56-
Set-Location -LiteralPath $oldLocation -ErrorAction SilentlyContinue
57-
}
58-
}
59-
60-
return $result
61-
}
62-
63-
# Original isolated process execution for display
6430
$executable = Get-PowerShellExecutable
6531
$scriptDirectory = [System.IO.Path]::GetDirectoryName($ScriptPath)
6632
$process = $null
@@ -86,6 +52,15 @@ function Invoke-ColorScriptProcess {
8652
$startInfo.StandardOutputEncoding = [System.Text.Encoding]::UTF8
8753
$startInfo.StandardErrorEncoding = [System.Text.Encoding]::UTF8
8854

55+
if ($ForCache) {
56+
try {
57+
$startInfo.EnvironmentVariables['COLOR_SCRIPTS_ENHANCED_CACHE_BUILD'] = '1'
58+
}
59+
catch {
60+
Write-Verbose ("Unable to set cache build environment variable: {0}" -f $_.Exception.Message)
61+
}
62+
}
63+
8964
if ($scriptDirectory) {
9065
$startInfo.WorkingDirectory = $scriptDirectory
9166
}

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.1634</UICultureVersion>
7+
<UICultureVersion>2025.11.05.1912</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.1634</UICultureVersion>
7+
<UICultureVersion>2025.11.05.1912</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.1634</UICultureVersion>
7+
<UICultureVersion>2025.11.05.1912</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.1634</UICultureVersion>
7+
<UICultureVersion>2025.11.05.1912</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.1634</UICultureVersion>
7+
<UICultureVersion>2025.11.05.1912</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.1634</UICultureVersion>
7+
<UICultureVersion>2025.11.05.1912</UICultureVersion>
88
</UICulture>
99
</SupportedUICultures>
1010
</HelpInfo>

0 commit comments

Comments
 (0)