-
Notifications
You must be signed in to change notification settings - Fork 0
/
AoC.ps1
98 lines (77 loc) · 2.61 KB
/
AoC.ps1
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
function New-Solution {
param (
[Parameter(Mandatory=$true, HelpMessage="The name of the new AoC Solution, typically Day04.")]
[string]
$ProjectName
)
dotnet new aoc-solution -n $ProjectName -o $ProjectName
dotnet sln AoC2021.sln add "$ProjectName/src/$ProjectName.csproj"
dotnet sln AoC2021.sln add "$ProjectName/test/$ProjectName.Test.csproj"
}
function Newest-Package($paths) {
$sorted = $paths |
where { $_.Name -match "AoC\.$ProjectName\.\d+\.\d+\.\d+.nupkg" } |
Select-Object -Property FullName, @{
Name = 'Version';
Expression = { [version]$($_.Name | Select-String -Pattern "Aoc.$ProjectName.(\d+.\d+.\d+).nupkg").Matches.Groups[1].ToString() }
} |
Sort-Object -Descending -Property 'Version'
return $sorted[0].FullName
}
function Publish-Lib {
param (
[Parameter(Mandatory=$true)]
[string]
$ProjectName
)
$projectFile = ".\$ProjectName\$ProjectName.csproj"
dotnet clean $projectFile
dotnet pack --include-symbols --include-source $ProjectFile
$nugetPath = Newest-Package(ls ".\$ProjectName\bin\debug\*.nupkg")
dotnet nuget push -s Local $nugetPath
$nugetSymbolsPath = $nugetPath -replace ".nupkg$", ".symbols.nupkg"
dotnet nuget push -s Local $nugetSymbolsPath
}
function Set-Current($name) {
$env:AOC_CUR="$name"
Write-Host "Set current day to $name"
}
function Get-SolutionName($name) {
return $name ?? $env:AOC_CUR
}
function Run-Solution($name) {
$name = Get-SolutionName($name)
pushd $name/src
dotnet run
popd
}
function Build-Solution($name) {
$name = Get-SolutionName($name)
dotnet build ./$name/test/$name.Test.csproj
}
function Test-Solution($name) {
$name = Get-SolutionName($name)
dotnet test ./$name/test/$name.Test.csproj
}
function AoC() {
$action = $args[0]
switch($action) {
"new" { New-Solution($args[1]); Set-Current($args[1]) }
"publish-lib" { Publish-Lib($args[1]) }
"cur" { Set-Current($args[1]) }
"build" { Build-Solution($args[1]) }
"run" { Run-Solution($args[1]) }
"test" { Test-Solution($args[1]) }
default {
Write-Host "Unrecognized command $($action)"
Write-Host "Commands:"
Write-Host " aoc new <Name>"
Write-Host " aoc publish-lib <Name>"
Write-Host ""
Write-Host " aoc cur <Name>"
Write-Host " aoc build <Name>"
Write-Host " aoc run <Name>"
Write-Host " aoc test <Name>"
}
}
}