-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild-Deploy.ps1
More file actions
134 lines (114 loc) · 5.04 KB
/
Build-Deploy.ps1
File metadata and controls
134 lines (114 loc) · 5.04 KB
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
<#
.SYNOPSIS
Build and deploy MarkdownPointer PowerShell module.
.DESCRIPTION
Builds the MarkdownPointer application and MCP server, then deploys
the PowerShell module to the system modules directory.
.PARAMETER AppOnly
Build and deploy only the App (skip MCP server).
.PARAMETER SkipBuild
Skip the build step and only deploy existing outputs.
.EXAMPLE
.\Build-Deploy.ps1
# Full build and deploy
.EXAMPLE
.\Build-Deploy.ps1 -AppOnly
# Build and deploy App only
#>
[CmdletBinding()]
param(
[switch]$AppOnly,
[switch]$SkipBuild
)
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
$ProjectRoot = $PSScriptRoot
$AppProject = Join-Path $ProjectRoot 'MarkdownPointer\MarkdownPointer.App.csproj'
$McpProject = Join-Path $ProjectRoot 'MarkdownPointer.Mcp\MarkdownPointer.Mcp.csproj'
$ModuleDir = Join-Path $ProjectRoot 'Module'
$BuildDir = Join-Path $ProjectRoot 'dist'
$InstallDir = Join-Path $env:ProgramFiles 'PowerShell\7\Modules\MarkdownPointer'
$InstallBinDir = Join-Path $InstallDir 'bin'
# Get version from App project
$csprojContent = Get-Content $AppProject -Raw
if ($csprojContent -match '<Version>([^<]+)</Version>') {
$Version = $Matches[1]
} else {
$Version = '0.1.0'
}
Write-Host '=== MarkdownPointer Build & Deploy ===' -ForegroundColor Cyan
Write-Host "Version: $Version" -ForegroundColor DarkGray
# Step 1: Stop running processes
Write-Host "`n[1/4] Stopping running processes..." -ForegroundColor Yellow
$names = if ($AppOnly) { @('mdp') } else { @('mdp', 'mdp-mcp') }
$processes = @(Get-Process -Name $names -ErrorAction Ignore)
if ($processes.Count -gt 0) {
$processes | Stop-Process -Force
Start-Sleep -Milliseconds 500
Write-Host " Stopped $($processes.Count) process(es)." -ForegroundColor Green
} else {
Write-Host ' No running processes found.' -ForegroundColor DarkGray
}
# Step 2: Build
if (-not $SkipBuild) {
Write-Host "`n[2/4] Building projects..." -ForegroundColor Yellow
# Always clean before build to ensure embedded resources are up to date
Write-Host " Cleaning..." -ForegroundColor DarkGray
dotnet clean $AppProject -c Release -v q --nologo 2>&1 | Out-Null
if (-not $AppOnly) {
dotnet clean $McpProject -c Release -v q --nologo 2>&1 | Out-Null
}
Write-Host " Building MarkdownPointer.App..." -ForegroundColor DarkGray
dotnet publish $AppProject -c Release -r win-x64 --no-self-contained -o "$BuildDir\app"
if ($LASTEXITCODE -ne 0) { throw "App build failed" }
if (-not $AppOnly) {
Write-Host " Building MarkdownPointer.Mcp..." -ForegroundColor DarkGray
dotnet publish $McpProject -c Release -r win-x64 --no-self-contained -o "$BuildDir\mcp"
if ($LASTEXITCODE -ne 0) { throw "MCP build failed" }
}
Write-Host ' Build succeeded.' -ForegroundColor Green
} else {
Write-Host "`n[2/4] Skipping build (SkipBuild specified)" -ForegroundColor DarkGray
}
# Step 3: Sync module version
Write-Host "`n[3/4] Syncing module version..." -ForegroundColor Yellow
$psd1Path = Join-Path $ModuleDir 'MarkdownPointer.psd1'
$psd1Content = Get-Content $psd1Path -Raw
$psd1Content = $psd1Content -replace "ModuleVersion\s*=\s*'[^']*'", "ModuleVersion = '$Version'"
Set-Content $psd1Path -Value $psd1Content -NoNewline
Write-Host " ModuleVersion = '$Version'" -ForegroundColor DarkGray
# Step 4: Deploy to module directory
Write-Host "`n[4/4] Deploying to $InstallDir ..." -ForegroundColor Yellow
if (-not (Test-Path $InstallBinDir)) {
New-Item $InstallBinDir -ItemType Directory -Force | Out-Null
}
# Clean stale files from bin (single-file publish bundles DLLs into exe)
$keepFiles = @('mdp.exe', 'mdp-mcp.exe', 'blank-template.pptx', 'Export-Slides.ps1')
$staleFiles = Get-ChildItem $InstallBinDir | Where-Object { $_.Name -notin $keepFiles }
if ($staleFiles) {
$staleFiles | Remove-Item -Force
Write-Host " Removed $($staleFiles.Count) stale file(s): $($staleFiles.Name -join ', ')" -ForegroundColor DarkGray
}
# Module files
Copy-Item "$ModuleDir\MarkdownPointer.psd1" $InstallDir -Force
Copy-Item "$ModuleDir\MarkdownPointer.psm1" $InstallDir -Force
Copy-Item "$PSScriptRoot\LICENSE" $InstallDir -Force -ErrorAction SilentlyContinue
# App binary
Copy-Item "$BuildDir\app\mdp.exe" $InstallBinDir -Force
# MCP binary + SlideKit assets
if (-not $AppOnly) {
$mcpExe = Get-ChildItem "$BuildDir\mcp" -Filter '*.exe' | Select-Object -First 1
Copy-Item $mcpExe.FullName "$InstallBinDir\mdp-mcp.exe" -Force
# SlideKit assets (PPTX template and PowerPoint export script)
foreach ($asset in @('blank-template.pptx', 'Export-Slides.ps1')) {
$assetPath = Join-Path "$BuildDir\mcp" $asset
if (Test-Path $assetPath) {
Copy-Item $assetPath $InstallBinDir -Force
}
}
}
Write-Host "`n=== Deployed to $InstallDir ===" -ForegroundColor Green
Get-ChildItem "$InstallBinDir\*.exe" | ForEach-Object {
$size = if ($_.Length -gt 1MB) { "{0:N1} MB" -f ($_.Length / 1MB) } else { "{0:N0} KB" -f ($_.Length / 1KB) }
Write-Host " $($_.Name) ($size)" -ForegroundColor Gray
}