86 lines
3.0 KiB
PowerShell
86 lines
3.0 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Packs Q-SYS plugin folders into .nupkg files.
|
|
|
|
.DESCRIPTION
|
|
For each plugin folder under plugins/ (or a single one via -Plugin):
|
|
1. Loads the plugin's .nuspec
|
|
2. Replaces the <description> element with the contents of
|
|
description.md, if that file exists next to the nuspec
|
|
3. Packs it into a .nupkg using `dotnet pack` (no Visual Studio needed)
|
|
|
|
Output lands in -OutputDir (default: dist/).
|
|
|
|
.EXAMPLE
|
|
./tools/pack.ps1 # pack every plugin
|
|
./tools/pack.ps1 -Plugin ExamplePlugin # pack one plugin
|
|
#>
|
|
[CmdletBinding()]
|
|
param(
|
|
[string]$Plugin,
|
|
[string]$OutputDir = "dist"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$repoRoot = Split-Path -Parent $PSScriptRoot
|
|
$pluginsDir = Join-Path $repoRoot "plugins"
|
|
$packProj = Join-Path $PSScriptRoot "pack.csproj"
|
|
$OutputDir = [System.IO.Path]::GetFullPath((Join-Path $repoRoot $OutputDir))
|
|
New-Item -ItemType Directory -Force -Path $OutputDir | Out-Null
|
|
|
|
# Which plugin folders to pack?
|
|
$targets = if ($Plugin) {
|
|
$dir = Join-Path $pluginsDir $Plugin
|
|
if (-not (Test-Path $dir)) { throw "Plugin folder not found: $dir" }
|
|
Get-Item $dir
|
|
} else {
|
|
Get-ChildItem $pluginsDir -Directory
|
|
}
|
|
|
|
$packed = @()
|
|
foreach ($dir in $targets) {
|
|
$nuspec = Get-ChildItem $dir.FullName -Filter *.nuspec | Select-Object -First 1
|
|
if (-not $nuspec) {
|
|
Write-Warning "Skipping $($dir.Name): no .nuspec found"
|
|
continue
|
|
}
|
|
|
|
# Load nuspec and inject description.md if present
|
|
[xml]$xml = Get-Content $nuspec.FullName -Raw
|
|
$descFile = Join-Path $dir.FullName "description.md"
|
|
if (Test-Path $descFile) {
|
|
$desc = (Get-Content $descFile -Raw).Trim()
|
|
# NuGet caps description at 4000 chars
|
|
if ($desc.Length -gt 4000) { $desc = $desc.Substring(0, 4000) }
|
|
$node = $xml.package.metadata.GetElementsByTagName("description")[0]
|
|
if (-not $node) {
|
|
$node = $xml.CreateElement("description", $xml.package.NamespaceURI)
|
|
$xml.package.metadata.AppendChild($node) | Out-Null
|
|
}
|
|
$node.InnerText = $desc # InnerText handles XML escaping
|
|
Write-Host " [$($dir.Name)] description injected from description.md"
|
|
}
|
|
|
|
$id = $xml.package.metadata.id
|
|
$version = $xml.package.metadata.version
|
|
|
|
# Write the effective nuspec to a temp file (source nuspec stays untouched)
|
|
$tmpNuspec = Join-Path ([System.IO.Path]::GetTempPath()) "$id.$version.nuspec"
|
|
$xml.Save($tmpNuspec)
|
|
|
|
Write-Host " [$($dir.Name)] packing $id $version ..."
|
|
dotnet pack $packProj `
|
|
-p:NuspecFile=$tmpNuspec `
|
|
-p:NuspecBasePath=$($dir.FullName) `
|
|
-o $OutputDir --nologo -v quiet
|
|
if ($LASTEXITCODE -ne 0) { throw "dotnet pack failed for $($dir.Name)" }
|
|
|
|
Remove-Item $tmpNuspec -ErrorAction SilentlyContinue
|
|
$pkg = Join-Path $OutputDir "$id.$version.nupkg"
|
|
$packed += $pkg
|
|
Write-Host " [$($dir.Name)] -> $pkg" -ForegroundColor Green
|
|
}
|
|
|
|
if ($packed.Count -eq 0) { throw "Nothing was packed." }
|
|
Write-Host "`nPacked $($packed.Count) package(s) into $OutputDir"
|