-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild.ps1
86 lines (71 loc) · 3.17 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
<#
.SYNOPSIS
Builds the SearchEngines plugin
.DESCRIPTION
This script builds and packages the SearchEngines plugin. It also
copies the build to the PowerToys Run Plugins directory.
i.e. `%LOCALAPPDATA%\Microsoft\PowerToys\PowerToys Run\Plugins`
.EXAMPLE
.\Build.ps1
Builds the SearchEngines plugin using the defaults
.EXAMPLE
.\Build.ps1 -Platform x64
Builds the SearchEngines plugin for the x64 platform
#>
[CmdletBinding()]
param(
# The name of the project
[string] $ProjectName = "SearchEngines",
# The platform to build the project for. Must be one of: x64, ARM64
[ValidateSet("x64", "ARM64")]
[string] $Platform = "x64",
# The configuration to build the project for. Must be one of: Debug, Release
[ValidateSet("Debug", "Release")]
[string] $Configuration = "Release",
# The target framework to build the project for.
[string] $TargetFramework = "net8.0-windows",
# The output directory for the build artifacts
[string] $OutDir = "$PSScriptRoot\Dist",
# The path to the PowerToys executable
[ValidateScript({ Test-Path -Path $_ -PathType Leaf })]
[string] $PowerToysPath = "C:\Program Files\PowerToys\PowerToys.exe"
)
# Constants
$ProjectFullName = "Community.PowerToys.Run.Plugin.$ProjectName" # Project FullName
$ProjectBinFolder = "$PSScriptRoot\$ProjectFullName\bin" # Project Bin Folder
$PowerToysRunPluginsDirectory = "$env:LOCALAPPDATA\Microsoft\PowerToys\PowerToys Run\Plugins" # PowerToys Run Plugins Directory
# Get Plugin Metadata
$PluginMetadata = Get-Content -Path "$PSScriptRoot\$ProjectFullName\plugin.json" | ConvertFrom-Json
$Version = $PluginMetadata.Version
# Stop running PowerToys process
Write-Host "Stopping PowerToys process..." -NoNewline
Stop-Process -Name "PowerToys" -Force -ErrorAction SilentlyContinue
Write-Host "✅"
# Clean the bin folder
Write-Host "Cleaning the bin folder..." -NoNewline
if (Test-Path -Path $ProjectBinFolder) {
Remove-Item -Path "$ProjectBinFolder\*" -Recurse -Force
}
Write-Host "✅"
# Build the project
Write-Host "`nBuilding the project..."
dotnet build "$PSScriptRoot\$ProjectFullName.sln" -c $Configuration /p:Platform=$Platform
Write-Host " "
# Prepare the build for packaging
Write-Host "Preparing the build for packaging..." -NoNewline
Remove-Item -Path "$ProjectBinFolder\*" -Recurse -Include *.xml, *.pdb, PowerToys.*, Wox.*
Write-Host "✅"
# Copy the build to the PowerToys Run Plugins directory
Write-Host "Copying the build to the PowerToys Run Plugins directory..." -NoNewline
Remove-Item -Path "$PowerToysRunPluginsDirectory\$ProjectName" -Recurse -Force -ErrorAction SilentlyContinue
Copy-Item -Path "$ProjectBinFolder\$Platform\$Configuration\$TargetFramework" -Destination "$PowerToysRunPluginsDirectory\$ProjectName" -Recurse -Force
Write-Host "✅"
# Package the project
Write-Host "Packaging the project..." -NoNewline
Compress-Archive -Path "$PowerToysRunPluginsDirectory\$ProjectName" -DestinationPath "$OutDir\$ProjectName-$Version-$Platform.zip" -Force
Write-Host "✅"
# Restart PowerToys
Write-Host "Restarting PowerToys..." -NoNewline
Start-Process -FilePath $PowerToysPath
Write-Host "✅"
Write-Host "`n📦 Build Completed Successfully ✅`n"