@@ -42,10 +42,10 @@ PARAM (
42
42
43
43
[Parameter ()]
44
44
[ValidateScript (
45
- { @ (" None" , " Errors" , " Changes" , " Skips" , " All" ) -match $_ },
45
+ { @ (' None' , ' Errors' , ' Changes' , ' Skips' , ' All' ) -match $_ },
46
46
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"" ."
47
47
)]
48
- [String ]$Log = " Changes"
48
+ [String ]$Log = ' Changes'
49
49
)
50
50
51
51
$Log = $Log.toLower ()
@@ -67,16 +67,16 @@ function Test-Fluff {
67
67
$InputObject.PSObject.Properties.Name -contains $For -and
68
68
-not $InputObject .$For
69
69
) -and
70
- $InputObject._copy._mod .$For -ne " remove"
70
+ $InputObject._copy._mod .$For -ne ' remove'
71
71
) {
72
72
if (
73
73
$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'
80
80
)
81
81
) {
82
82
Write-Output $true
@@ -92,13 +92,13 @@ function Test-Fluff {
92
92
93
93
if ((Test-Path $Path )) {
94
94
$target = Get-Item $Path
95
- if ($target.Extension -eq " .json" ) {
95
+ if ($target.Extension -eq ' .json' ) {
96
96
try {
97
97
$brew = Get-Content $target - Encoding Utf8 | ConvertFrom-Json
98
98
} 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 )
102
102
}
103
103
}
104
104
if ($brew.monsterFluff ) {
@@ -123,23 +123,51 @@ if ((Test-Path $Path)) {
123
123
)
124
124
125
125
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' ))
128
128
}
129
129
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' ))
132
132
}
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' ))
135
135
}
136
136
} 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' ) {
141
169
Write-Error " $target is not a `` .json`` "
142
170
}
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