|
| 1 | +# Pre-publish check script |
| 2 | +# Validates module integrity and best practices before publishing |
| 3 | + |
| 4 | +$ModulePath = ".\code365scripts.openai" |
| 5 | +$ModuleName = "code365scripts.openai" |
| 6 | + |
| 7 | +Write-Host "🔍 PowerShell Module Pre-publish Check" -ForegroundColor Green |
| 8 | +Write-Host "Module path: $ModulePath" -ForegroundColor Cyan |
| 9 | +Write-Host "" |
| 10 | + |
| 11 | +$issues = @() |
| 12 | +$warnings = @() |
| 13 | + |
| 14 | +# 1. Check module manifest |
| 15 | +Write-Host "1️⃣ Checking module manifest (.psd1)" -ForegroundColor Yellow |
| 16 | +try { |
| 17 | + $manifest = Test-ModuleManifest -Path "$ModulePath\$ModuleName.psd1" -ErrorAction Stop |
| 18 | + Write-Host " ✅ Module manifest syntax is correct" -ForegroundColor Green |
| 19 | + Write-Host " 📊 Module version: $($manifest.Version)" -ForegroundColor Cyan |
| 20 | + Write-Host " 📊 PowerShell version requirement: $($manifest.PowerShellVersion)" -ForegroundColor Cyan |
| 21 | + Write-Host " 📊 Compatible editions: $($manifest.CompatiblePSEditions -join ', ')" -ForegroundColor Cyan |
| 22 | +} |
| 23 | +catch { |
| 24 | + $issues += "Module manifest validation failed: $_" |
| 25 | + Write-Host " ❌ Module manifest validation failed" -ForegroundColor Red |
| 26 | +} |
| 27 | + |
| 28 | +# 2. Check required files |
| 29 | +Write-Host "`n2️⃣ Checking required files" -ForegroundColor Yellow |
| 30 | +$requiredFiles = @( |
| 31 | + "$ModulePath\$ModuleName.psd1", |
| 32 | + "$ModulePath\$ModuleName.psm1" |
| 33 | +) |
| 34 | + |
| 35 | +foreach ($file in $requiredFiles) { |
| 36 | + if (Test-Path $file) { |
| 37 | + Write-Host " ✅ $($file | Split-Path -Leaf) exists" -ForegroundColor Green |
| 38 | + } |
| 39 | + else { |
| 40 | + $issues += "Missing required file: $file" |
| 41 | + Write-Host " ❌ $($file | Split-Path -Leaf) missing" -ForegroundColor Red |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +# 3. Check public functions |
| 46 | +Write-Host "`n3️⃣ Checking public functions" -ForegroundColor Yellow |
| 47 | +$publicFunctions = Get-ChildItem -Path "$ModulePath\Public" -Filter "*.ps1" | ForEach-Object { $_.BaseName } |
| 48 | +$exportedFunctions = $manifest.ExportedFunctions.Keys |
| 49 | + |
| 50 | +Write-Host " 📁 Functions in Public folder: $($publicFunctions -join ', ')" -ForegroundColor Cyan |
| 51 | +Write-Host " 📋 Functions exported in manifest: $($exportedFunctions -join ', ')" -ForegroundColor Cyan |
| 52 | + |
| 53 | +$missingExports = $publicFunctions | Where-Object { $_ -notin $exportedFunctions } |
| 54 | +$extraExports = $exportedFunctions | Where-Object { $_ -notin $publicFunctions } |
| 55 | + |
| 56 | +if ($missingExports) { |
| 57 | + $warnings += "The following functions are in Public folder but not exported in manifest: $($missingExports -join ', ')" |
| 58 | + Write-Host " ⚠️ Not exported: $($missingExports -join ', ')" -ForegroundColor Yellow |
| 59 | +} |
| 60 | + |
| 61 | +if ($extraExports) { |
| 62 | + $warnings += "The following functions are exported in manifest but not in Public folder: $($extraExports -join ', ')" |
| 63 | + Write-Host " ⚠️ Extra exports: $($extraExports -join ', ')" -ForegroundColor Yellow |
| 64 | +} |
| 65 | + |
| 66 | +if (-not $missingExports -and -not $extraExports) { |
| 67 | + Write-Host " ✅ Function export configuration is correct" -ForegroundColor Green |
| 68 | +} |
| 69 | + |
| 70 | +# 4. Check documentation |
| 71 | +Write-Host "`n4️⃣ Checking documentation" -ForegroundColor Yellow |
| 72 | +$docFiles = @("README.md", "CHANGELOG.md", "LICENSE") |
| 73 | +foreach ($doc in $docFiles) { |
| 74 | + if (Test-Path $doc) { |
| 75 | + Write-Host " ✅ $doc exists" -ForegroundColor Green |
| 76 | + } |
| 77 | + else { |
| 78 | + $warnings += "Recommend adding $doc file" |
| 79 | + Write-Host " ⚠️ $doc missing" -ForegroundColor Yellow |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +# 5. Check version information |
| 84 | +Write-Host "`n5️⃣ Checking version management" -ForegroundColor Yellow |
| 85 | +try { |
| 86 | + $onlineModule = Find-Module -Name $ModuleName -ErrorAction Stop |
| 87 | + if ($manifest.Version -gt $onlineModule.Version) { |
| 88 | + Write-Host " ✅ Version number correctly incremented ($($onlineModule.Version) → $($manifest.Version))" -ForegroundColor Green |
| 89 | + } |
| 90 | + elseif ($manifest.Version -eq $onlineModule.Version) { |
| 91 | + $issues += "Version number not updated, current version $($manifest.Version) is same as online version" |
| 92 | + Write-Host " ❌ Version number not updated" -ForegroundColor Red |
| 93 | + } |
| 94 | + else { |
| 95 | + $issues += "Version number rolled back, current version $($manifest.Version) is lower than online version $($onlineModule.Version)" |
| 96 | + Write-Host " ❌ Version number rolled back" -ForegroundColor Red |
| 97 | + } |
| 98 | +} |
| 99 | +catch { |
| 100 | + Write-Host " 📦 New module, no need to check online version" -ForegroundColor Cyan |
| 101 | +} |
| 102 | + |
| 103 | +# 6. Syntax check |
| 104 | +Write-Host "`n6️⃣ PowerShell syntax check" -ForegroundColor Yellow |
| 105 | +$psFiles = Get-ChildItem -Path $ModulePath -Filter "*.ps1" -Recurse |
| 106 | +$syntaxErrors = @() |
| 107 | + |
| 108 | +foreach ($file in $psFiles) { |
| 109 | + try { |
| 110 | + $null = [System.Management.Automation.PSParser]::Tokenize((Get-Content $file.FullName -Raw), [ref]$null) |
| 111 | + Write-Host " ✅ $($file.Name) syntax correct" -ForegroundColor Green |
| 112 | + } |
| 113 | + catch { |
| 114 | + $syntaxErrors += "$($file.Name): $_" |
| 115 | + Write-Host " ❌ $($file.Name) syntax error" -ForegroundColor Red |
| 116 | + } |
| 117 | +} |
| 118 | + |
| 119 | +if ($syntaxErrors) { |
| 120 | + $issues += $syntaxErrors |
| 121 | +} |
| 122 | + |
| 123 | +# Summary |
| 124 | +Write-Host "`n📋 Check Summary" -ForegroundColor Green |
| 125 | +Write-Host "=" * 50 |
| 126 | + |
| 127 | +if ($issues.Count -eq 0 -and $warnings.Count -eq 0) { |
| 128 | + Write-Host "🎉 Congratulations! Module is ready for publishing!" -ForegroundColor Green |
| 129 | +} |
| 130 | +else { |
| 131 | + if ($issues.Count -gt 0) { |
| 132 | + Write-Host "❌ Found $($issues.Count) issues that must be fixed:" -ForegroundColor Red |
| 133 | + $issues | ForEach-Object { Write-Host " • $_" -ForegroundColor Red } |
| 134 | + } |
| 135 | + |
| 136 | + if ($warnings.Count -gt 0) { |
| 137 | + Write-Host "⚠️ Found $($warnings.Count) recommendations for improvement:" -ForegroundColor Yellow |
| 138 | + $warnings | ForEach-Object { Write-Host " • $_" -ForegroundColor Yellow } |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +if ($issues.Count -eq 0) { |
| 143 | + Write-Host "`n🚀 You can publish the module using:" -ForegroundColor Cyan |
| 144 | + Write-Host " .\publish.ps1 -NuGetApiKey 'your-api-key'" -ForegroundColor White |
| 145 | + Write-Host " .\publish.ps1 -NuGetApiKey 'your-api-key' -WhatIf # Preview mode" -ForegroundColor White |
| 146 | +} |
0 commit comments