Skip to content

Commit 0a8139f

Browse files
committed
🚜 [refactor] Rework core private helpers, localization and caching flows
- Introduce Resolve-LocalizedMessagesFile: robust, culture-aware discovery for Messages.psd1 (case-insensitive dir matching, culture fallback, safe resolution) and integrate into Import-LocalizedMessagesFromFile. - Rework Import-LocalizedMessagesFromFile / Initialize-ColorScriptsLocalization to probe multiple candidate roots, attempt per-candidate imports, select the first successful localized file, populate $script:LocalizationDetails (LocalizedDataLoaded/ModuleRoot/SearchedPaths/Source/FilePath) and gracefully fall back to embedded defaults with improved Write-ModuleTrace messages. - Consolidate synchronization and delegate usage (Invoke-ModuleSynchronized + delegates) to make path/IO behaviors more testable and resilient. - Preserve previous private helper snapshot under scripts/original-PrivateFunctions.ps1 for reference. ✨ [feat] Harden path resolution, cache & inventory behavior - Resolve-CachePath: safer tilde (~) expansion via GetUserProfilePathDelegate with fallbacks to $HOME, validate drive qualifiers, and return $null for unresolved/invalid roots to avoid surprising IO operations. - Initialize-CacheDirectory / Get-CachedOutput: initialize cache directory on demand, return consistent pscustomobject for missing/invalid state, and avoid throwing where not actionable. - Get-ColorScriptInventory: avoid unnecessary full refreshes by detecting non-file entries in the cached inventory, probe file counts as a lightweight check, and preserve ScriptInventoryRecords / -Raw semantics. - Invoke-ColorScriptProcess (fast in-process path): switch working directory using Get-Location -PSProvider FileSystem, capture all output streams with *>&1 for accurate cached output, and ensure working directory is restored. - Allow Invoke-FileWriteAllText to accept empty content (AllowEmptyString) for explicit empty-file writes. 🛠️ [fix] Improve public cmdlets: profile handling, scaffolding and cache UX - Add-ColorScriptProfile: detect remote hosts (PSSenderInfo) and avoid unsupported remote updates; robustly resolve PROFILE variants (PSObject / CurrentUserAllHosts), use Resolve-CachePath / session-based path fallbacks, honor configuration defaults, add SkipStartupScript and structured return {Path,Changed,Message}, and surface localized errors when resolution fails. - New-ColorScript: add a 'Scaffold' ParameterSet, rename Destination→OutputPath, add Force/GenerateMetadataSnippet/Category/Tag support, produce a scaffold file + optional metadata guidance, call Reset-ScriptInventoryCache after creation, use ShouldProcess and return a structured metadata object on success. - New-ColorScriptCache (alias Build-ColorScriptCache): add alias and default parameter set, accept pipeline input and accumulate Name patterns, normalize selection via Select-RecordsByName, metadata-driven selection (Category/Tag), progress reporting, consistent structured result records (Status/Message/ExitCode/StdOut/StdErr) and human-readable summary via Write-ColorScriptInformation; better handling for PassThru. - Clear-ColorScriptCache: complete rewrite to support Name/Category/Tag/Path/All/DryRun/PassThru with pipeline-friendly name collection, pattern vs metadata matching, per-file Invoke-ShouldProcess checks, explicit status states (Removed/Missing/DryRun/Skipped/Errors), and a summarized informational output when not returning PassThru. 🔧 [build] Module manifest & export list updates - Add 'Build-ColorScriptCache' to ColorScripts-Enhanced.psd1 AliasesToExport and to Export-ModuleMember -Alias in the module file so the new alias is exported consistently. 🧪 [test] Add import coverage tests and preserve original helpers - Add comprehensive Tests/ColorScripts-Enhanced.ModuleImportCoverage.Tests.ps1 to validate trace configuration parsing, trace-file preparation/fallback, module-root discovery, and robust import behavior when Private/Public folders are unavailable. - Add scripts/original-PrivateFunctions.ps1 to keep a snapshot of the prior private implementation for easier review/debugging. - Remove stale test-output.txt. 🧹 [chore] Formatting, completions and small cleanups - Tidy argument-completer scriptblocks and indentation (Get-ColorScriptList, Show-ColorScript) to improve readability and avoid subtle completion bugs; remove duplicate NoAnsiOutput assignments in Show-ColorScript. - Minor trailing-newline / whitespace fixes added to multiple public files (Export-ColorScriptMetadata, Get-ColorScriptConfiguration, Reset-ColorScriptConfiguration, Set-ColorScriptConfiguration). - Small message / error-id clarifications and more consistent use of structured result objects across public cmdlets to improve downstream automation and tests. Signed-off-by: Nick2bad4u <20943337+Nick2bad4u@users.noreply.github.com>
1 parent 9d9505d commit 0a8139f

16 files changed

Lines changed: 4566 additions & 569 deletions

ColorScripts-Enhanced/ColorScripts-Enhanced.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ PERFECT FOR
138138
VariablesToExport = @()
139139

140140
# 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.
141-
AliasesToExport = @('scs', 'Update-ColorScriptCache')
141+
AliasesToExport = @('scs', 'Update-ColorScriptCache', 'Build-ColorScriptCache')
142142

143143
# DSC resources to export from this module
144144
# DscResourcesToExport = @()

ColorScripts-Enhanced/ColorScripts-Enhanced.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ Export-ModuleMember -Function @(
363363
'Reset-ColorScriptConfiguration',
364364
'Export-ColorScriptMetadata',
365365
'New-ColorScript'
366-
) -Alias @('scs', 'Update-ColorScriptCache')
366+
) -Alias @('scs', 'Update-ColorScriptCache', 'Build-ColorScriptCache')
367367

368368
if ($script:Messages -and $script:Messages.ContainsKey('ModuleLoadedSuccessfully')) {
369369
Write-Verbose $script:Messages.ModuleLoadedSuccessfully

0 commit comments

Comments
 (0)