Skip to content

Commit 8ff1883

Browse files
committed
suffering for lyra
1 parent c0c77c6 commit 8ff1883

File tree

3 files changed

+116
-28
lines changed

3 files changed

+116
-28
lines changed

Diff for: URL-tester.ps1

+31-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,37 @@ switch ($target.Attributes) {
5656
break
5757
}
5858
Directory {
59-
$files = @(Get-ChildItem $target -File -Recurse -Exclude 'node_modules' | Where-Object { $_.Extension -eq '.json' })
59+
$baseFiles = Get-ChildItem $target -File
60+
$i = $baseFiles.Name.IndexOf('.gitignore')
61+
if ($i -ne -1) {
62+
$gitignore = Get-Content $baseFiles[$i] -Encoding utf8 |
63+
Where-Object { $_ -and $_ -notmatch '^#' } |
64+
ForEach-Object {
65+
# Escape .
66+
# Convert * to any character
67+
# Convert ? to any single character
68+
# dir/ matches sub-paths
69+
# /xyz matches only within root
70+
# [!...] becomes [^...]
71+
# Make path-separators neutral
72+
$_ -replace '\.', '\.' `
73+
-replace '\*', '.*' `
74+
-replace '\?', '.' `
75+
-replace '/$', '/.+' `
76+
-replace '^/', [Regex]::Escape($target) `
77+
-replace '\[!([^]]+)\]', '[^$1]' `
78+
-replace '/', '[/|\\]'
79+
}
80+
$gitignore += 'package\.json$'
81+
$gitignore += 'package-lock\.json$'
82+
$files = @(
83+
Get-ChildItem $target -File -Recurse | Where-Object {
84+
$_.Extension -eq '.json' -and -not (Select-String -Quiet -Pattern $gitignore -InputObject $_.FullName)
85+
}
86+
)
87+
} else {
88+
$files = @(Get-ChildItem $target -File -Recurse | Where-Object { $_.Extension -eq '.json' })
89+
}
6090
if (-not $files.Count) {
6191
Write-Error "No JSON files found in $([System.IO.Path]::GetRelativePath($PWD.Path, $target.FullName))" -ErrorAction Stop
6292
}

Diff for: creature-fluff-tagger.ps1

+54-26
Original file line numberDiff line numberDiff line change
@@ -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

9393
if ((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+
}

Diff for: tag-checker.ps1

+31-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,37 @@ switch ($target.Attributes) {
141141
break
142142
}
143143
Directory {
144-
$files = @(Get-ChildItem $target -File -Recurse -Exclude 'node_modules' | Where-Object { $_.Extension -eq '.json' })
144+
$baseFiles = Get-ChildItem $target -File
145+
$i = $baseFiles.Name.IndexOf('.gitignore')
146+
if ($i -ne -1) {
147+
$gitignore = Get-Content $baseFiles[$i] -Encoding utf8 |
148+
Where-Object { $_ -and $_ -notmatch '^#' } |
149+
ForEach-Object {
150+
# Escape .
151+
# Convert * to any character
152+
# Convert ? to any single character
153+
# dir/ matches sub-paths
154+
# /xyz matches only within root
155+
# [!...] becomes [^...]
156+
# Make path-separators neutral
157+
$_ -replace '\.', '\.' `
158+
-replace '\*', '.*' `
159+
-replace '\?', '.' `
160+
-replace '/$', '/.+' `
161+
-replace '^/', [Regex]::Escape($target) `
162+
-replace '\[!([^]]+)\]', '[^$1]' `
163+
-replace '/', '[/|\\]'
164+
}
165+
$gitignore += 'package\.json$'
166+
$gitignore += 'package-lock\.json$'
167+
$files = @(
168+
Get-ChildItem $target -File -Recurse | Where-Object {
169+
$_.Extension -eq '.json' -and -not (Select-String -Quiet -Pattern $gitignore -InputObject $_.FullName)
170+
}
171+
)
172+
} else {
173+
$files = @(Get-ChildItem $target -File -Recurse | Where-Object { $_.Extension -eq '.json' })
174+
}
145175
if (-not $files.Count) {
146176
throw "No JSON files found in $($target.FullName)"
147177
exit 1

0 commit comments

Comments
 (0)