|
1 | | -function ConvertTo-RelativePath { |
2 | | - param( |
3 | | - [Parameter(Mandatory)] |
4 | | - [string]$Path |
5 | | - ) |
6 | | - |
7 | | - # 1) Remove everything up to and including "outputs/module/" (case-insensitive), |
8 | | - # allowing either slash or backslash. |
9 | | - $relative = $Path -replace '(?i)^.*outputs[\\/]+module[\\/]+', '' |
10 | | - |
11 | | - # 2) Convert all backslashes to forward slashes for consistency |
12 | | - $relative = $relative -replace '\\', '/' |
13 | | - |
14 | | - # 3) Remove the *next* folder (the module name) in the path. |
15 | | - # For example, "PSModuleTest/scripts/loader.ps1" => "scripts/loader.ps1" |
16 | | - $segments = $relative -split '/' |
17 | | - if ($segments.Count -gt 1) { |
18 | | - # Skip the first segment (the module name) and rejoin the rest |
19 | | - $relative = ($segments[1..($segments.Count - 1)]) -join '/' |
20 | | - } else { |
21 | | - # If there was only one segment, just keep it (file in the root) |
22 | | - $relative = $segments[0] |
23 | | - } |
24 | | - |
25 | | - return $relative |
26 | | -} |
27 | | - |
28 | | -function Normalize-IndentationExceptFirst { |
| 1 | +function Normalize-IndentationExceptFirst { |
29 | 2 | [CmdletBinding()] |
30 | 3 | param( |
31 | 4 | [Parameter(Mandatory)] |
@@ -77,35 +50,3 @@ function Normalize-IndentationExceptFirst { |
77 | 50 | # Reconstruct the final code: first line + adjusted subsequent lines |
78 | 51 | return ($firstLine + $newLine + ($subsequentLines -join $newLine)) |
79 | 52 | } |
80 | | - |
81 | | - |
82 | | -# Improve path normalization by using PSModulePath |
83 | | -function ConvertTo-NormalizedModulePath { |
84 | | - [CmdletBinding()] |
85 | | - param( |
86 | | - [Parameter(Mandatory, ValueFromPipeline)] |
87 | | - [string] $Path |
88 | | - ) |
89 | | - |
90 | | - process { |
91 | | - # Normalize backslashes to forward slashes for consistency |
92 | | - $Path = $Path.Replace('\', '/') |
93 | | - |
94 | | - # Get only the first module path and normalize it |
95 | | - $modulePath = ($env:PSModulePath -split [IO.Path]::PathSeparator | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | |
96 | | - Select-Object -First 1).TrimEnd('\', '/').Replace('\', '/') |
97 | | - |
98 | | - if ($modulePath -and $Path -match [regex]::Escape($modulePath)) { |
99 | | - # Remove the module path prefix |
100 | | - $normalizedPath = $Path -replace [regex]::Escape($modulePath), '' |
101 | | - # Remove any leading path separators |
102 | | - $normalizedPath = $normalizedPath.TrimStart('/') |
103 | | - |
104 | | - # Return with the standard "Modules/" prefix |
105 | | - return "Modules/$normalizedPath" |
106 | | - } |
107 | | - |
108 | | - # If no match found, just normalize slashes and return the original path |
109 | | - return $Path |
110 | | - } |
111 | | -} |
0 commit comments