-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.build.ps1
129 lines (103 loc) · 2.95 KB
/
.build.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
<#
# Dependency Versions
#>
$Versions = @{
DotNetCore = '3.1.5'
}
<#
# Helper Functions
#>
function Test-PodeBuildIsWindows
{
$v = $PSVersionTable
return ($v.Platform -ilike '*win*' -or ($null -eq $v.Platform -and $v.PSEdition -ieq 'desktop'))
}
function Test-PodeBuildCommand($cmd)
{
$path = $null
if (Test-PodeBuildIsWindows) {
$path = (Get-Command $cmd -ErrorAction Ignore)
}
else {
$path = (which $cmd)
}
return (![string]::IsNullOrWhiteSpace($path))
}
function Invoke-PodeBuildInstall($name, $version)
{
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
if (Test-PodeBuildIsWindows) {
if (Test-PodeBuildCommand 'choco') {
choco install $name --version $version -y
}
}
else {
if (Test-PodeBuildCommand 'brew') {
brew install $name
}
elseif (Test-PodeBuildCommand 'apt-get') {
sudo apt-get install $name -y
}
elseif (Test-PodeBuildCommand 'yum') {
sudo yum install $name -y
}
}
}
<#
# Dependencies
#>
# Synopsis: Install dependencies for compiling/building
task BuildDeps {
# install dotnet
if (!(Test-PodeBuildCommand 'dotnet')) {
Invoke-PodeBuildInstall 'dotnetcore' $Versions.DotNetCore
}
}
<#
# Packaging
#>
# Synopsis: Package up the Module
task Pack -If (Test-PodeBuildIsWindows) Build, {
$path = './pkg'
if (Test-Path $path) {
Remove-Item -Path $path -Recurse -Force | Out-Null
}
# create the pkg dir
New-Item -Path $path -ItemType Directory -Force | Out-Null
# which folders do we need?
$folders = @('Public', 'Libs')
# create the directories, then copy the source
$folders | ForEach-Object {
New-Item -ItemType Directory -Path (Join-Path $path $_) -Force | Out-Null
Copy-Item -Path "./src/$($_)/*" -Destination (Join-Path $path $_) -Force | Out-Null
}
# copy general files
Copy-Item -Path ./src/Pode.Kestrel.psm1 -Destination $path -Force | Out-Null
Copy-Item -Path ./src/Pode.Kestrel.psd1 -Destination $path -Force | Out-Null
Copy-Item -Path ./LICENSE.txt -Destination $path -Force | Out-Null
}
<#
# Building
#>
# Synopsis: Build the .NET Core Listener
task Build BuildDeps, {
if (Test-Path ./src/Libs) {
Remove-Item -Path ./src/Libs -Recurse -Force | Out-Null
}
Push-Location ./src/Listener
try {
dotnet build --configuration Release
if (!$?) {
throw 'Build Failed'
}
dotnet publish --configuration Release --self-contained --output ../Libs
if (!$?) {
throw 'Publish Failed'
}
exec { nuget install Microsoft.AspNetCore.App -Version 2.2.5 -OutputDirectory ../Listener/nuget }
(Get-ChildItem ../Listener/nuget -Filter *.dll -Recurse) | ForEach-Object { Copy-Item -Path $_.FullName -Destination ../Libs -Force }
}
finally {
Pop-Location
}
}