-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddTaskComments.ps1
More file actions
51 lines (39 loc) · 1.35 KB
/
AddTaskComments.ps1
File metadata and controls
51 lines (39 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
param (
[string]$SolutionPath = $null
)
function Add-Comments {
$yearFolders = Get-ChildItem -Directory -Filter "Year*"
$lineEnding = "`r`n"
foreach ($folder in $yearFolders) {
$year = $folder.Name -replace 'Year ', ''
$codeFiles = Get-ChildItem -Path "$($folder.FullName)\*" -Recurse -File |
Where-Object { $_.Extension -in '.cs', '.fs' }
foreach ($file in $codeFiles) {
$day = ($file.BaseName -replace '[^0-9]', '').TrimStart('0')
$comment = "// Task: https://adventofcode.com/$year/day/$day"
$lines = Get-Content $file.FullName -Raw
$lineArray = $lines -split $lineEnding
if (-not ($lineArray[0] -match '^//')) {
$lineArray = @($comment, "") + $lineArray
}
$updatedContent = ($lineArray -join $lineEnding)
[System.IO.File]::WriteAllText($file.FullName, $updatedContent, [System.Text.Encoding]::UTF8)
}
}
Write-Host "All Challenge Solution files have been updated."
}
try
{
$originalLocation = Get-Location
$baseFolderPath = if (-not $SolutionPath) { "$originalLocation\Advent of Code\Challenge Solutions"} else {$SolutionPath}
Set-Location $baseFolderPath
Add-Comments
}
catch
{
Write-Error "An error occurred: $_"
}
finally
{
Set-Location $originalLocation
}