forked from beto-rodriguez/LiveCharts2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpack.ps1
156 lines (130 loc) · 5.02 KB
/
pack.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
[string]$configuration = "Release"
[string]$nupkgOutputPath = "./nupkg"
[Project[]]$projects = @(
[Project]::new("./src/LiveChartsCore/LiveChartsCore.csproj")
[Project]::new("./src/skiasharp/LiveChartsCore.SkiaSharp/LiveChartsCore.SkiaSharpView.csproj")
[Project]::new("./src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/LiveChartsCore.SkiaSharpView.Avalonia.csproj")
[Project]::new("./src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/LiveChartsCore.SkiaSharpView.WinForms.csproj")
[Project]::new("./src/skiasharp/LiveChartsCore.SkiaSharp.Wpf/LiveChartsCore.SkiaSharpView.Wpf.csproj")
[Project]::new("./src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/LiveChartsCore.SkiaSharpView.Xamarin.Forms.csproj")
[Project]::new("./src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/LiveChartsCore.SkiaSharpView.Blazor.csproj")
[Project]::new("./src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/LiveChartsCore.SkiaSharpView.Eto.csproj")
[Project]::new("./src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/LiveChartsCore.SkiaSharpView.Maui.csproj")
[Project]::new("./src/skiasharp/LiveChartsCore.SkiaSharpView.Uno/LiveChartsCore.SkiaSharpView.Uno.csproj", $true)
[Project]::new("./src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/LiveChartsCore.SkiaSharpView.Uno.WinUI.csproj", $true)
[Project]::new(
"./src/skiasharp/LiveChartsCore.SkiaSharpView.WinUI/LiveChartsCore.SkiaSharpView.WinUI.csproj",
$true,
"nuget",
"./src/skiasharp/LiveChartsCore.SkiaSharpView.WinUI/LiveChartsCore.SkiaSharpView.WinUI.nuspec"
)
)
$msbuild = &"${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe
class Project {
[string]$src
[bool]$useMsbuild
[string]$packingMethod ## dotnet | msbuild | nuget
[string]$nuspecFile
Project(
[string]$src
) {
$this.src = $src
$this.useMsbuild = $false
$this.packingMethod = "dotnet"
$this.nuspecFile = $null
}
Project(
[string]$src,
[bool]$useMsbuild
) {
$this.src = $src
$this.useMsbuild = $useMsbuild
if ($useMsbuild) {
$this.packingMethod = "msbuild"
$this.nuspecFile = ""
}
}
Project(
[string]$src,
[bool]$useMsbuild,
[string]$packingMethod,
[string]$nuspecFile
) {
$this.src = $src
$this.useMsbuild = $useMsbuild
$this.packingMethod = $packingMethod
$this.nuspecFile = $nuspecFile
}
[string]GetFolder() {
return $this.src.SubString(0, $this.src.LastIndexOf("/"));
}
}
function Add-Build {
param (
[Project] $project
)
$folder = $project.GetFolder()
if (Test-Path $($folder + "/bin")) {
Remove-Item $($folder + "/bin") -Force -Recurse
}
if ($project.useMsbuild) {
# skip the build, it will be built in the pack method.
if ($project.packingMethod -ne "msbuild") {
& $msbuild $project.src /p:configuration=$configuration /restore
}
}
else {
dotnet build $project.src -c $configuration
}
if ($LastExitCode -ne 0) {
throw $("failed at '" + $project.src + "' with exit code " + $LastExitCode);
}
}
function Add-Pack {
param (
[Project] $project
)
if ($project.packingMethod -eq "dotnet") {
dotnet pack $project.src -o $nupkgOutputPath -c $configuration --no-build
}
if ($project.packingMethod -eq "msbuild") {
& $msbuild $project.src -t:pack /p:configuration=$configuration
$folder = $project.GetFolder()
$found = Get-ChildItem $folder -Filter "*.nupkg" -Recurse -Force
Copy-Item $found.FullName $nupkgOutputPath
$found = Get-ChildItem $folder -Filter "*.snupkg" -Recurse -Force
Copy-Item $found.FullName $nupkgOutputPath
}
if ($project.packingMethod -eq "nuget") {
if (!(Test-Path "./nuget.exe")) {
Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile "./nuget.exe"
}
./nuget pack $project.nuspecFile -OutputDirectory $nupkgOutputPath -Symbols
}
}
function Write-ColorOutput($foregroundColor)
{
# save the current color
$fc = $host.UI.RawUI.ForegroundColor
# set the new color
$host.UI.RawUI.ForegroundColor = $foregroundColor
# output
if ($args) {
Write-Output $args
}
else {
$input | Write-Output
}
# restore the original color
$host.UI.RawUI.ForegroundColor = $fc
}
if (Test-Path $nupkgOutputPath) {
Get-ChildItem $nupkgOutputPath -Include *.* -File -Recurse | ForEach-Object { $_.Delete() }
} else {
New-Item $nupkgOutputPath -ItemType "directory"
}
foreach ($p in $projects) {
Add-Build $p
Add-Pack $p
}
Write-ColorOutput green $("`n`nSuccessfully built and packed " + $projects.length + " projects at '" + $nupkgOutputPath + "' using '" + $configuration + "' config.`n`n")