Skip to content

Commit fa142e3

Browse files
committed
Rewrite and simplify build system
1 parent d14f950 commit fa142e3

File tree

6 files changed

+39
-560
lines changed

6 files changed

+39
-560
lines changed

.gitignore

+5-46
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,6 @@
1-
*.swp
2-
*.*~
3-
project.lock.json
4-
.DS_Store
5-
*.pyc
6-
nupkg/
7-
8-
# Rider
9-
.idea
10-
11-
# User-specific files
12-
*.suo
13-
*.user
14-
*.userosscache
15-
*.sln.docstates
16-
17-
# Build results
18-
[Dd]ebug/
19-
[Dd]ebugPublic/
20-
[Rr]elease/
21-
[Rr]eleases/
22-
x64/
23-
x86/
24-
build/
25-
bld/
26-
[Bb]in/
27-
[Oo]bj/
28-
[Oo]ut/
29-
msbuild.log
30-
msbuild.err
31-
msbuild.wrn
32-
33-
#Module build
341
module/
35-
36-
# Visual Studio 2015
37-
.vs/
38-
39-
# ingore downloaded .NET
40-
.dotnet
41-
42-
# Ignore package
43-
Microsoft.PowerShell.GraphicalTools.zip
44-
Microsoft.PowerShell.ConsoleGuiTools.zip
45-
46-
# git artifacts
47-
*.orig
2+
out/
3+
bin/
4+
obj/
5+
publish/
6+
*.sln

Build.ps1

-58
This file was deleted.

ConsoleGuiTools.build.ps1

+33-94
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,50 @@
11

22
param(
33
[ValidateSet("Debug", "Release")]
4-
[string]$Configuration = "Debug",
5-
6-
[string[]]$ModuleName = @("Microsoft.PowerShell.ConsoleGuiTools" )
4+
[string]$Configuration = "Debug"
75
)
86

9-
$script:TargetFramework = "net6.0"
10-
11-
$script:ModuleLayouts = @{}
12-
foreach ($mn in $ModuleName) {
13-
$script:ModuleLayouts.$mn = Import-PowerShellDataFile -Path "$PSScriptRoot/src/$mn/ModuleLayout.psd1"
14-
}
15-
167
task FindDotNet -Before Clean, Build {
17-
Assert (Get-Command dotnet -ErrorAction SilentlyContinue) "dotnet not found, please install it: https://aka.ms/dotnet-cli"
18-
19-
# Strip out semantic version metadata so it can be cast to `Version`
20-
[Version]$existingVersion, $null = (dotnet --version) -split " " -split "-"
21-
Assert ($existingVersion -ge [Version]("6.0")) ".NET SDK 6.0 or higher is required, please update it: https://aka.ms/dotnet-cli"
22-
23-
Write-Host "Using dotnet v$(dotnet --version) at path $((Get-Command dotnet).Source)" -ForegroundColor Green
24-
}
25-
26-
task Build {
27-
Remove-Item $PSScriptRoot/module -Recurse -Force -ErrorAction Ignore
28-
29-
foreach ($moduleLayout in $script:ModuleLayouts.Values) {
30-
foreach ($projName in $moduleLayout.RequiredBuildAssets.Keys) {
31-
exec { & dotnet publish -c $Configuration "$PSScriptRoot/src/$projName/$projName.csproj" }
32-
}
33-
34-
foreach ($nativeProj in $moduleLayout.NativeBuildAssets.Keys) {
35-
foreach ($targetPlatform in $moduleLayout.NativeBuildAssets[$nativeProj]) {
36-
$buildPropertyParams = if ($targetPlatform -eq "win-x64") {
37-
"/property:IsWindows=true"
38-
}
39-
else {
40-
"/property:IsWindows=false"
41-
}
42-
exec { & dotnet publish -c $Configuration "$PSScriptRoot/src/$nativeProj/$nativeProj.csproj" -r $targetPlatform $buildPropertyParams }
43-
}
44-
}
45-
}
8+
Assert (Get-Command dotnet -ErrorAction SilentlyContinue) "The dotnet CLI was not found, please install it: https://aka.ms/dotnet-cli"
9+
$DotnetVersion = dotnet --version
10+
Assert ($?) "The required .NET SDK was not found, please install it: https://aka.ms/dotnet-cli"
11+
Write-Host "Using dotnet $DotnetVersion at path $((Get-Command dotnet).Source)" -ForegroundColor Green
4612
}
4713

4814
task Clean {
49-
Remove-BuildItem $PSScriptRoot/module
50-
51-
foreach ($moduleLayout in $script:ModuleLayouts.Values) {
52-
foreach ($projName in $moduleLayout.RequiredBuildAssets.Keys) {
53-
exec { & dotnet clean -c $Configuration "$PSScriptRoot/src/$projName/$projName.csproj" }
54-
}
55-
56-
foreach ($projName in $moduleLayout.NativeBuildAssets.Keys) {
57-
exec { & dotnet clean -c $Configuration "$PSScriptRoot/src/$projName/$projName.csproj" }
58-
}
59-
}
15+
Remove-BuildItem ./module, ./out
16+
Push-Location src/Microsoft.PowerShell.ConsoleGuiTools
17+
Invoke-BuildExec { & dotnet clean }
18+
Pop-Location
6019
}
6120

62-
task LayoutModule -After Build {
63-
foreach ($mn in $ModuleName) {
64-
$moduleLayout = $script:ModuleLayouts[$mn]
65-
$moduleBinPath = "$PSScriptRoot/module/$mn/"
66-
67-
# Create the destination dir
68-
$null = New-Item -Force $moduleBinPath -Type Directory
69-
70-
# For each subproject
71-
foreach ($projectName in $moduleLayout.RequiredBuildAssets.Keys) {
72-
# Get the project build dir path
73-
$basePath = [System.IO.Path]::Combine($PSScriptRoot, 'src', $projectName, 'bin', $Configuration, $script:TargetFramework)
74-
75-
# For each asset in the subproject
76-
foreach ($bin in $moduleLayout.RequiredBuildAssets[$projectName]) {
77-
# Get the asset path
78-
$binPath = Join-Path $basePath $bin
79-
80-
# Binplace the asset
81-
Copy-Item -Force -Verbose $binPath $moduleBinPath
82-
}
83-
}
84-
85-
foreach ($projectName in $moduleLayout.NativeBuildAssets.Keys) {
86-
foreach ($targetPlatform in $moduleLayout.NativeBuildAssets[$projectName]) {
87-
$destDir = Join-Path $moduleBinPath $projectName $targetPlatform
88-
89-
$null = New-Item -Force $destDir -Type Directory
90-
91-
# Get the project build dir path
92-
$publishPath = [System.IO.Path]::Combine($PSScriptRoot, 'src', $projectName, 'bin', $Configuration, $script:TargetFramework, $targetPlatform, "publish\*" )
93-
94-
Write-Host $publishPath
95-
# Binplace the asset
96-
Copy-Item -Recurse -Force $publishPath $destDir
97-
}
98-
}
99-
100-
Copy-Item -Force "$PSScriptRoot/README.md" $moduleBinPath
101-
Copy-Item -Force "$PSScriptRoot/LICENSE.txt" $moduleBinPath
21+
task Build {
22+
New-Item -ItemType Directory -Force ./module | Out-Null
23+
24+
Push-Location src/Microsoft.PowerShell.ConsoleGuiTools
25+
Invoke-BuildExec { & dotnet publish --configuration $Configuration --output publish }
26+
$Assets = $(
27+
"../../README.md",
28+
"../../LICENSE.txt",
29+
"./publish/Microsoft.PowerShell.ConsoleGuiTools.dll",
30+
"./publish/Microsoft.PowerShell.ConsoleGuiTools.psd1",
31+
"./publish/Microsoft.PowerShell.OutGridView.Models.dll",
32+
"./publish/Terminal.Gui.dll",
33+
"./publish/NStack.dll")
34+
$Assets | ForEach-Object {
35+
Copy-Item -Force -Path $_ -Destination ../../module
10236
}
37+
Pop-Location
38+
39+
New-ExternalHelp -Path docs/Microsoft.PowerShell.ConsoleGuiTools -OutputPath module/en-US -Force
10340
}
10441

105-
task BuildCmdletHelp {
106-
foreach ($mn in $ModuleName) {
107-
New-ExternalHelp -Path "$PSScriptRoot/docs/$mn" -OutputPath "$PSScriptRoot/module/$mn/en-US" -Force
42+
task Package {
43+
New-Item -ItemType Directory -Force ./out | Out-Null
44+
if (-Not (Get-PSResourceRepository -Name ConsoleGuiTools -ErrorAction SilentlyContinue)) {
45+
Register-PSResourceRepository -Name ConsoleGuiTools -Uri ./out
10846
}
47+
Publish-PSResource -Path ./module -Repository ConsoleGuiTools -Verbose
10948
}
11049

111-
task . Clean, Build, BuildCmdletHelp
50+
task . Clean, Build

0 commit comments

Comments
 (0)