@@ -42,10 +42,10 @@ PARAM (
4242
4343 [Parameter ()]
4444 [ValidateScript (
45- { @ (" None" , " Errors" , " Changes" , " Skips" , " All" ) -match $_ },
45+ { @ (' None' , ' Errors' , ' Changes' , ' Skips' , ' All' ) -match $_ },
4646 ErrorMessage = " Cannot bind parameter 'Log' due to enumeration values that are not valid. Select one of the following enumeration values and try again. The possible enumeration values are "" None"" , "" Errors"" , "" Changes"" , "" Skips"" , "" All"" ."
4747 )]
48- [String ]$Log = " Changes"
48+ [String ]$Log = ' Changes'
4949)
5050
5151$Log = $Log.toLower ()
@@ -67,16 +67,16 @@ function Test-Fluff {
6767 $InputObject.PSObject.Properties.Name -contains $For -and
6868 -not $InputObject .$For
6969 ) -and
70- $InputObject._copy._mod .$For -ne " remove"
70+ $InputObject._copy._mod .$For -ne ' remove'
7171 ) {
7272 if (
7373 $InputObject._copy._mod .$For.mode -in @ (
74- " appendArr"
75- " prependArr"
76- " replaceArr"
77- " insertArr"
78- " replaceOrAppendArr"
79- " appendIfNotExistsArr"
74+ ' appendArr'
75+ ' prependArr'
76+ ' replaceArr'
77+ ' insertArr'
78+ ' replaceOrAppendArr'
79+ ' appendIfNotExistsArr'
8080 )
8181 ) {
8282 Write-Output $true
@@ -92,13 +92,13 @@ function Test-Fluff {
9292
9393if ((Test-Path $Path )) {
9494 $target = Get-Item $Path
95- if ($target.Extension -eq " .json" ) {
95+ if ($target.Extension -eq ' .json' ) {
9696 try {
9797 $brew = Get-Content $target - Encoding Utf8 | ConvertFrom-Json
9898 } catch {
99- if ($Log -ne " none" ) {
100- Write-Host " " - NoNewLine
101- Write-Warning (" Invalid JSON in " + $target )
99+ if ($Log -ne ' none' ) {
100+ Write-Host ' ' - NoNewline
101+ Write-Warning (' Invalid JSON in ' + $target )
102102 }
103103 }
104104 if ($brew.monsterFluff ) {
@@ -123,23 +123,51 @@ if ((Test-Path $Path)) {
123123 )
124124
125125 if ($tagsApplied ) {
126- if ($Log -in @ (" changes" , " all" )) {
127- Write-Host (" Tagged " + ($target -replace ' ^.*[\\/]([^\\/]+[\\/][^\\/]+)$' , ' $1' ))
126+ if ($Log -in @ (' changes' , ' all' )) {
127+ Write-Host (' Tagged ' + ($target -replace ' ^.*[\\/]([^\\/]+[\\/][^\\/]+)$' , ' $1' ))
128128 }
129129 ConvertTo-Json $brew - Depth 99 | Out-File - FilePath $target - Encoding Utf8
130- } elseif ($Log -in @ (" skips" , " all" )) {
131- Write-Host (" Left unchanged " + ($target -replace ' ^.*[\\/]([^\\/]+[\\/][^\\/]+)$' , ' $1' ))
130+ } elseif ($Log -in @ (' skips' , ' all' )) {
131+ Write-Host (' Left unchanged ' + ($target -replace ' ^.*[\\/]([^\\/]+[\\/][^\\/]+)$' , ' $1' ))
132132 }
133- } elseif ($Log -in @ (" skips" , " all" )) {
134- Write-Host (" Left unchanged " + ($target -replace ' ^.*[\\/]([^\\/]+[\\/][^\\/]+)$' , ' $1' ))
133+ } elseif ($Log -in @ (' skips' , ' all' )) {
134+ Write-Host (' Left unchanged ' + ($target -replace ' ^.*[\\/]([^\\/]+[\\/][^\\/]+)$' , ' $1' ))
135135 }
136136 } elseif ($target.Attributes.HasFlag ([System.IO.FileAttributes ]::Directory)) {
137- Get-ChildItem $target - Recurse - File |
138- Where-Object { $_.Extension -eq ' .json' } |
139- ForEach-Object { . $PSCommandPath - Path $_ - Log $Log }
140- } elseif ($Log -ne " none" ) {
137+ $baseFiles = Get-ChildItem $target - File
138+ $i = $baseFiles.Name.IndexOf (' .gitignore' )
139+ if ($i -ne -1 ) {
140+ $gitignore = Get-Content $baseFiles [$i ] - Encoding utf8 |
141+ Where-Object { $_ -and $_ -notmatch ' ^#' } |
142+ ForEach-Object {
143+ # Escape .
144+ # Convert * to any character
145+ # Convert ? to any single character
146+ # dir/ matches sub-paths
147+ # /xyz matches only within root
148+ # [!...] becomes [^...]
149+ # Make path-separators neutral
150+ $_ -replace ' \.' , ' \.' `
151+ -replace ' \*' , ' .*' `
152+ -replace ' \?' , ' .' `
153+ -replace ' /$' , ' /.+' `
154+ -replace ' ^/' , [Regex ]::Escape($target ) `
155+ -replace ' \[!([^]]+)\]' , ' [^$1]' `
156+ -replace ' /' , ' [/|\\]'
157+ }
158+ $gitignore += ' package\.json$'
159+ $gitignore += ' package-lock\.json$'
160+ Get-ChildItem $target - Recurse - File |
161+ Where-Object { $_.Extension -eq ' .json' -and -not (Select-String - Quiet - Pattern $gitignore - InputObject $_.FullName ) } |
162+ ForEach-Object { . $PSCommandPath - Path $_ - Log $Log }
163+ } else {
164+ Get-ChildItem $target - Recurse - File |
165+ Where-Object { $_.Extension -eq ' .json' } |
166+ ForEach-Object { . $PSCommandPath - Path $_ - Log $Log }
167+ }
168+ } elseif ($Log -ne ' none' ) {
141169 Write-Error " $target is not a `` .json`` "
142170 }
143- } elseif ($Log -ne " none" ) {
144- Write-Error " File/directory not found"
145- }
171+ } elseif ($Log -ne ' none' ) {
172+ Write-Error ' File/directory not found'
173+ }
0 commit comments