|
| 1 | +# NuGet Package Build Script for Windows PowerShell |
| 2 | +# This script builds and packs the Language Server Framework for NuGet |
| 3 | + |
| 4 | +param( |
| 5 | + [string]$Version = "", |
| 6 | + [switch]$SkipTests = $false, |
| 7 | + [switch]$Help = $false |
| 8 | +) |
| 9 | + |
| 10 | +if ($Help) { |
| 11 | + Write-Host @" |
| 12 | +NuGet Package Build Script |
| 13 | +
|
| 14 | +Usage: |
| 15 | + .\pack.ps1 [-Version <version>] [-SkipTests] [-Help] |
| 16 | +
|
| 17 | +Parameters: |
| 18 | + -Version <version> : Specify package version (e.g., 1.0.0) |
| 19 | + -SkipTests : Skip running tests before packing |
| 20 | + -Help : Show this help message |
| 21 | +
|
| 22 | +Examples: |
| 23 | + .\pack.ps1 |
| 24 | + .\pack.ps1 -Version 1.0.0 |
| 25 | + .\pack.ps1 -Version 1.0.0 -SkipTests |
| 26 | +
|
| 27 | +"@ |
| 28 | + exit 0 |
| 29 | +} |
| 30 | + |
| 31 | +Write-Host "========================================" -ForegroundColor Cyan |
| 32 | +Write-Host " Language Server Framework - Pack" -ForegroundColor Cyan |
| 33 | +Write-Host "========================================" -ForegroundColor Cyan |
| 34 | +Write-Host "" |
| 35 | + |
| 36 | +# Clean previous artifacts |
| 37 | +Write-Host "[1/5] Cleaning previous artifacts..." -ForegroundColor Yellow |
| 38 | +if (Test-Path "artifacts") { |
| 39 | + Remove-Item -Recurse -Force "artifacts" |
| 40 | +} |
| 41 | +New-Item -ItemType Directory -Path "artifacts" | Out-Null |
| 42 | +Write-Host "✓ Cleaned" -ForegroundColor Green |
| 43 | +Write-Host "" |
| 44 | + |
| 45 | +# Restore dependencies |
| 46 | +Write-Host "[2/5] Restoring dependencies..." -ForegroundColor Yellow |
| 47 | +dotnet restore |
| 48 | +if ($LASTEXITCODE -ne 0) { |
| 49 | + Write-Host "✗ Restore failed!" -ForegroundColor Red |
| 50 | + exit $LASTEXITCODE |
| 51 | +} |
| 52 | +Write-Host "✓ Restored" -ForegroundColor Green |
| 53 | +Write-Host "" |
| 54 | + |
| 55 | +# Build |
| 56 | +Write-Host "[3/5] Building in Release mode..." -ForegroundColor Yellow |
| 57 | +dotnet build --configuration Release --no-restore |
| 58 | +if ($LASTEXITCODE -ne 0) { |
| 59 | + Write-Host "✗ Build failed!" -ForegroundColor Red |
| 60 | + exit $LASTEXITCODE |
| 61 | +} |
| 62 | +Write-Host "✓ Built" -ForegroundColor Green |
| 63 | +Write-Host "" |
| 64 | + |
| 65 | +# Run tests (optional) |
| 66 | +if (-not $SkipTests) { |
| 67 | + Write-Host "[4/5] Running tests..." -ForegroundColor Yellow |
| 68 | + dotnet test --configuration Release --no-build --verbosity normal |
| 69 | + if ($LASTEXITCODE -ne 0) { |
| 70 | + Write-Host "✗ Tests failed!" -ForegroundColor Red |
| 71 | + exit $LASTEXITCODE |
| 72 | + } |
| 73 | + Write-Host "✓ Tests passed" -ForegroundColor Green |
| 74 | +} else { |
| 75 | + Write-Host "[4/5] Skipping tests..." -ForegroundColor Yellow |
| 76 | +} |
| 77 | +Write-Host "" |
| 78 | + |
| 79 | +# Pack |
| 80 | +Write-Host "[5/5] Creating NuGet package..." -ForegroundColor Yellow |
| 81 | +$packArgs = @( |
| 82 | + "pack" |
| 83 | + "LanguageServer.Framework\LanguageServer.Framework.csproj" |
| 84 | + "--configuration", "Release" |
| 85 | + "--no-build" |
| 86 | + "--output", "artifacts" |
| 87 | +) |
| 88 | + |
| 89 | +if ($Version) { |
| 90 | + $packArgs += "-p:PackageVersion=$Version" |
| 91 | + Write-Host "Using version: $Version" -ForegroundColor Cyan |
| 92 | +} |
| 93 | + |
| 94 | +& dotnet $packArgs |
| 95 | +if ($LASTEXITCODE -ne 0) { |
| 96 | + Write-Host "✗ Pack failed!" -ForegroundColor Red |
| 97 | + exit $LASTEXITCODE |
| 98 | +} |
| 99 | +Write-Host "✓ Packed" -ForegroundColor Green |
| 100 | +Write-Host "" |
| 101 | + |
| 102 | +# List created packages |
| 103 | +Write-Host "========================================" -ForegroundColor Cyan |
| 104 | +Write-Host " Package Created Successfully!" -ForegroundColor Green |
| 105 | +Write-Host "========================================" -ForegroundColor Cyan |
| 106 | +Write-Host "" |
| 107 | +Write-Host "Package location: .\artifacts\" -ForegroundColor Cyan |
| 108 | +Get-ChildItem -Path "artifacts" -Filter "*.nupkg" | ForEach-Object { |
| 109 | + Write-Host " - $($_.Name)" -ForegroundColor White |
| 110 | + Write-Host " Size: $([math]::Round($_.Length / 1KB, 2)) KB" -ForegroundColor Gray |
| 111 | +} |
| 112 | +Write-Host "" |
| 113 | + |
| 114 | +# Show next steps |
| 115 | +Write-Host "Next steps:" -ForegroundColor Yellow |
| 116 | +Write-Host " 1. Test locally: dotnet nuget push .\artifacts\*.nupkg --source local-feed" -ForegroundColor White |
| 117 | +Write-Host " 2. Publish to NuGet: dotnet nuget push .\artifacts\*.nupkg --api-key YOUR_KEY --source https://api.nuget.org/v3/index.json" -ForegroundColor White |
| 118 | +Write-Host " 3. Or use GitHub Actions for automated publishing" -ForegroundColor White |
| 119 | +Write-Host "" |
0 commit comments