Skip to content

Commit e315754

Browse files
committed
🚜 [refactor] Rename Build-ColorScriptCache → New-ColorScriptCache, add Update-ColorScriptCache alias and propagate changes
- ✨ [feat] Introduce New-ColorScriptCache as the public cmdlet (rename of Build-ColorScriptCache) and register alias Update-ColorScriptCache; bump module manifest version/date and export aliases. - 🚜 [refactor] Replace Build-ColorScriptCache references across the codebase (ColorScripts-Enhanced.psm1/psd1, scripts/, tests/, build tooling, generated help, README and docs/), adding New-ColorScriptCache usages and help pages. - 🛠️ [fix] Add ConvertFrom-JsonToHashtable helper for PowerShell 5.1 compatibility and switch JSON cache parsing to use it; normalize Set-Content invocation when writing JSON caches. - 🧪 [test] Update Pester tests to assert New-ColorScriptCache export and behavior; adapt test calls and expectations accordingly. - 🧹 [chore] Add .coverage tooling and documentation (.coverage/README.md, .gitignore, DebugCoverageTests.ps1, ShowCoverageSummary.ps1, metadata-cache-test.ps1), add context7.json, and adjust repo config (.gitignore, .mega-linter.yml) and generated dist/release notes. - 📝 [docs] Add en-US New-ColorScriptCache help file, update help XML and all docs/examples to reference the new command name. - 🎨 [style] Minor content fixes (http→https in assets, "TODO List" → "Improvements List") and refresh generated HelpInfo UICultureVersion. Signed-off-by: Nick2bad4u <20943337+Nick2bad4u@users.noreply.github.com>
1 parent 3bbaed1 commit e315754

49 files changed

Lines changed: 1261 additions & 1060 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.coverage/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Ignore coverage output files
2+
*.xml
3+
coverage-report/
4+
*.html
5+
*.css
6+
*.js

.coverage/DebugCoverageTests.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
$result = Invoke-Pester -Path "./Tests/ColorScripts-Enhanced.CoverageExpansion.Tests.ps1" -PassThru -Output None
2+
Write-Host "Failed: $($result.FailedCount)"
3+
foreach ($failed in $result.Failed) {
4+
Write-Host '---'
5+
Write-Host $failed.Name
6+
Write-Host $failed.FailureMessage
7+
if ($failed.ErrorRecord) {
8+
Write-Host $failed.ErrorRecord.Exception.GetType().FullName
9+
Write-Host $failed.ErrorRecord.Exception.Message
10+
Write-Host $failed.ErrorRecord.InvocationInfo.PositionMessage
11+
Write-Host $failed.ErrorRecord.ScriptStackTrace
12+
}
13+
}

.coverage/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Code Coverage
2+
3+
This directory contains code coverage reports generated by Pester tests.
4+
5+
## Files
6+
7+
- `coverage.xml` - JaCoCo format coverage data (uploaded to Codecov)
8+
- `coverage-report/` - HTML coverage reports (generated with ReportGenerator)
9+
10+
## Generating Coverage Reports
11+
12+
### Local Development
13+
14+
```powershell
15+
# Run tests with coverage
16+
./scripts/Test-Coverage.ps1
17+
18+
# Run with HTML report
19+
./scripts/Test-Coverage.ps1 -ShowReport
20+
```
21+
22+
Or using npm scripts:
23+
24+
```powershell
25+
npm run test:coverage
26+
npm run test:coverage:report
27+
```
28+
29+
### CI/CD
30+
31+
Coverage is automatically collected and uploaded to Codecov on every push via GitHub Actions.
32+
33+
## Viewing Coverage
34+
35+
- **Online**: [Codecov Dashboard](https://codecov.io/gh/Nick2bad4u/ps-color-scripts-enhanced)
36+
- **Local HTML**: Open `coverage-report/index.html` after running with `-ShowReport`
37+
- **Badge**: ![codecov](https://codecov.io/gh/Nick2bad4u/ps-color-scripts-enhanced/branch/main/graph/badge.svg)
38+
39+
## Coverage Targets
40+
41+
- Minimum Coverage: 70%
42+
- Target Coverage: 80%+
43+
44+
## Files Excluded from Coverage
45+
46+
- `Scripts/` directory (colorscript files)
47+
- Test files themselves
48+
- Build/deployment scripts

.coverage/ShowCoverageSummary.ps1

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
param(
2+
[string]$Path = (Join-Path $PSScriptRoot 'coverage.clixml'),
3+
[int]$Top = 20,
4+
[string]$Function
5+
)
6+
7+
if (-not (Test-Path -LiteralPath $Path)) {
8+
Write-Error "Coverage file '$Path' not found."
9+
exit 1
10+
}
11+
12+
$cov = Import-Clixml -Path $Path
13+
$missed = $cov.CodeCoverage.CommandsMissed
14+
15+
if ($Function) {
16+
$functionMisses = $missed | Where-Object { $_.Function -eq $Function }
17+
if (-not $functionMisses) {
18+
Write-Host "No missed commands recorded for function '$Function'."
19+
return
20+
}
21+
22+
foreach ($miss in $functionMisses) {
23+
$location = "{0}:{1}" -f $miss.File, $miss.StartLine
24+
Write-Host $location -ForegroundColor Cyan
25+
if ($miss.Command) {
26+
Write-Host " $($miss.Command)"
27+
}
28+
else {
29+
Write-Host " [No command text captured]"
30+
}
31+
Write-Host
32+
}
33+
return
34+
}
35+
36+
$groups = $missed | Group-Object Function | Sort-Object Count -Descending
37+
$groups | Select-Object -First $Top | Format-Table -AutoSize

.coverage/metadata-cache-test.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Temporary debug script intentionally left empty.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,5 +348,4 @@ coverage.xml
348348
coverage-report/
349349
testResults.xml
350350
test-results.xml
351-
*.coverage
352351
!dist

.mega-linter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ MARKDOWN_MARKDOWN_TABLE_FORMATTER_FILTER_REGEX_EXCLUDE: '(CHANGELOG\.md|.*AUDIT.
3131
REPOSITORY_CHECKOV_ARGUMENTS: "--framework github_actions --skip-check CKV_GHA_7,CKV2_GHA_1"
3232
REPOSITORY_DEVSKIM_ARGUMENTS: "--ignore-globs **/node_modules/**,**/.git/**"
3333
REPOSITORY_GITLEAKS_CONFIG_FILE: .gitleaks.toml
34-
REPOSITORY_SECRETLINT_ARGUMENTS: "--secretlintrc .secretlintrc.json"
34+
# REPOSITORY_SECRETLINT_ARGUMENTS: "--secretlintrc .secretlintrc.json"
3535
REPOSITORY_TRIVY_ARGUMENTS: "--skip-dirs node_modules"
3636

3737
# YAML settings

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ By participating in this project, you agree to maintain a respectful and inclusi
6262
Show-ColorScript -Name my-cool-script
6363
6464
# Test caching
65-
Build-ColorScriptCache -Name my-cool-script
65+
New-ColorScriptCache -Name my-cool-script
6666
Show-ColorScript -Name my-cool-script
6767
```
6868

@@ -217,7 +217,7 @@ ps-color-scripts-enhanced/
217217
│ │ ├── about_ColorScripts-Enhanced.help.txt
218218
│ │ ├── Show-ColorScript.md
219219
│ │ ├── Get-ColorScriptList.md
220-
│ │ ├── Build-ColorScriptCache.md
220+
│ │ ├── New-ColorScriptCache.md
221221
│ │ └── Clear-ColorScriptCache.md
222222
│ └── Scripts/ # Colorscript files
223223
│ ├── hearts.ps1

ColorScripts-Enhanced/ColorScripts-Enhanced.psd1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
#
44
# Generated by: Nick2bad4u
55
#
6-
# Generated on: 10/29/2025
6+
# Generated on: 10/30/2025
77
#
88

99
@{
1010
# Script module or binary module file associated with this manifest.
1111
RootModule = 'ColorScripts-Enhanced.psm1'
1212

1313
# Version number of this module.
14-
ModuleVersion = '2025.10.29.2019'
14+
ModuleVersion = '2025.10.30.0107'
1515

1616
# Supported PSEditions
1717
CompatiblePSEditions = @('Desktop', 'Core')
@@ -87,7 +87,7 @@ Full documentation: https://github.com/Nick2bad4u/ps-color-scripts-enhanced
8787
FunctionsToExport = @(
8888
'Show-ColorScript'
8989
'Get-ColorScriptList'
90-
'Build-ColorScriptCache'
90+
'New-ColorScriptCache'
9191
'Clear-ColorScriptCache'
9292
'Add-ColorScriptProfile'
9393
'Get-ColorScriptConfiguration'
@@ -104,7 +104,7 @@ Full documentation: https://github.com/Nick2bad4u/ps-color-scripts-enhanced
104104
VariablesToExport = @()
105105

106106
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
107-
AliasesToExport = @('scs')
107+
AliasesToExport = @('scs', 'Update-ColorScriptCache')
108108

109109
# DSC resources to export from this module
110110
# DscResourcesToExport = @()
@@ -172,7 +172,7 @@ Full documentation: https://github.com/Nick2bad4u/ps-color-scripts-enhanced
172172

173173
# ReleaseNotes of this module
174174
ReleaseNotes = @'
175-
Version 2025.10.29.2019:
175+
Version 2025.10.30.0107:
176176
- Enhanced caching system with OS-wide cache in AppData
177177
- 6-19x performance improvement
178178
- Cache stored in centralized location

ColorScripts-Enhanced/ColorScripts-Enhanced.psm1

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,64 @@ $script:IsWindows = $IsWindows
3737
$script:IsMacOS = $IsMacOS
3838
$script:PowerShellMajorVersion = $PSVersionTable.PSVersion.Major
3939

40+
function ConvertFrom-JsonToHashtable {
41+
<#
42+
.SYNOPSIS
43+
Converts JSON to a hashtable, compatible with PowerShell 5.1 and 7+
44+
.DESCRIPTION
45+
PowerShell 5.1 doesn't support -AsHashtable parameter on ConvertFrom-Json.
46+
This function provides a compatible conversion method for all PowerShell versions.
47+
#>
48+
param(
49+
[Parameter(Mandatory, ValueFromPipeline)]
50+
[AllowEmptyString()]
51+
[string]$InputObject
52+
)
53+
54+
process {
55+
if ([string]::IsNullOrWhiteSpace($InputObject)) {
56+
return $null
57+
}
58+
59+
# PowerShell 6.0+ supports -AsHashtable natively
60+
if ($PSVersionTable.PSVersion.Major -ge 6) {
61+
return ConvertFrom-Json -InputObject $InputObject -AsHashtable
62+
}
63+
64+
# PowerShell 5.1 fallback: Convert PSCustomObject to Hashtable
65+
function ConvertTo-HashtableInternal {
66+
param([Parameter(ValueFromPipeline)]$InputObject)
67+
68+
process {
69+
if ($null -eq $InputObject) {
70+
return $null
71+
}
72+
73+
if ($InputObject -is [System.Collections.IEnumerable] -and $InputObject -isnot [string]) {
74+
$collection = @()
75+
foreach ($item in $InputObject) {
76+
$collection += ConvertTo-HashtableInternal $item
77+
}
78+
return $collection
79+
}
80+
81+
if ($InputObject -is [PSCustomObject]) {
82+
$hash = @{}
83+
foreach ($property in $InputObject.PSObject.Properties) {
84+
$hash[$property.Name] = ConvertTo-HashtableInternal $property.Value
85+
}
86+
return $hash
87+
}
88+
89+
return $InputObject
90+
}
91+
}
92+
93+
$obj = ConvertFrom-Json -InputObject $InputObject
94+
return ConvertTo-HashtableInternal $obj
95+
}
96+
}
97+
4098
function Initialize-SystemDelegateState {
4199
if (-not $script:GetUserProfilePathDelegate) {
42100
$script:GetUserProfilePathDelegate = { [System.Environment]::GetFolderPath('UserProfile') }
@@ -443,7 +501,7 @@ function Initialize-Configuration {
443501
try {
444502
$raw = Get-Content -LiteralPath $script:ConfigurationPath -Raw -ErrorAction Stop
445503
if (-not [string]::IsNullOrWhiteSpace($raw)) {
446-
$existing = ConvertFrom-Json -InputObject $raw -AsHashtable
504+
$existing = ConvertFrom-JsonToHashtable -InputObject $raw
447505
}
448506
else {
449507
$raw = $null
@@ -1240,7 +1298,7 @@ function Get-ColorScriptMetadataTable {
12401298
if ($cacheFileInfo.LastWriteTimeUtc -ge $currentTimestamp) {
12411299
# JSON cache is current, load it
12421300
$jsonData = Get-Content -LiteralPath $binaryCachePath -Raw -ErrorAction Stop
1243-
$cachedHash = ConvertFrom-Json -InputObject $jsonData -AsHashtable -ErrorAction Stop
1301+
$cachedHash = ConvertFrom-JsonToHashtable -InputObject $jsonData
12441302

12451303
# Convert back to proper dictionary
12461304
$loadedStore = New-Object 'System.Collections.Generic.Dictionary[string, object]' ([System.StringComparer]::OrdinalIgnoreCase)
@@ -1645,7 +1703,7 @@ function Get-ColorScriptMetadataTable {
16451703
if ($binaryCachePath) {
16461704
try {
16471705
$jsonData = $store | ConvertTo-Json -Depth 10 -Compress
1648-
Set-Content -LiteralPath $binaryCachePath -Value $jsonData -Encoding UTF8 -ErrorAction Stop
1706+
Set-Content -Path $binaryCachePath -Value $jsonData -Encoding UTF8 -ErrorAction Stop
16491707
Write-Verbose "Saved metadata to JSON cache for faster future loads"
16501708
}
16511709
catch {
@@ -2516,9 +2574,10 @@ Limit the selection to scripts that belong to the specified category (case-insen
25162574
.PARAMETER Tag
25172575
Limit the selection to scripts containing the specified metadata tags (case-insensitive). Multiple values are treated as an OR filter.
25182576
#>
2519-
function Build-ColorScriptCache {
2577+
function New-ColorScriptCache {
25202578
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseOutputTypeCorrectly', '', Justification = 'Returns structured pipeline records for each cache operation.')]
25212579
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')]
2580+
[Alias('Update-ColorScriptCache')]
25222581
param(
25232582
[Parameter(ParameterSetName = 'Help')]
25242583
[Alias('help')]
@@ -2547,7 +2606,7 @@ function Build-ColorScriptCache {
25472606
begin {
25482607
$helpRequested = $false
25492608
if ($h) {
2550-
Show-ColorScriptHelp -CommandName 'Build-ColorScriptCache'
2609+
Show-ColorScriptHelp -CommandName 'New-ColorScriptCache'
25512610
$helpRequested = $true
25522611
return
25532612
}
@@ -2712,7 +2771,6 @@ function Build-ColorScriptCache {
27122771
default { 'White' }
27132772
}
27142773
$statusText = switch ($item.Status) {
2715-
'Updated' { 'Cached' }
27162774
'SkippedUpToDate' { 'Up-to-date (skipped)' }
27172775
'Failed' { 'Failed' }
27182776
'SkippedByUser' { 'Skipped by user' }
@@ -3430,15 +3488,15 @@ function Invoke-ColorScriptsStartup {
34303488
Export-ModuleMember -Function @(
34313489
'Show-ColorScript',
34323490
'Get-ColorScriptList',
3433-
'Build-ColorScriptCache',
3491+
'New-ColorScriptCache',
34343492
'Clear-ColorScriptCache',
34353493
'Add-ColorScriptProfile',
34363494
'Get-ColorScriptConfiguration',
34373495
'Set-ColorScriptConfiguration',
34383496
'Reset-ColorScriptConfiguration',
34393497
'Export-ColorScriptMetadata',
34403498
'New-ColorScript'
3441-
) -Alias @('scs')
3499+
) -Alias @('scs', 'Update-ColorScriptCache')
34423500

34433501
# Module initialization - cache and configuration are lazily loaded when first needed
34443502
Write-Verbose "ColorScripts-Enhanced module loaded successfully."

0 commit comments

Comments
 (0)