diff --git a/Prepare-StorePackage.ps1 b/Prepare-StorePackage.ps1 index 4238c4b5..f4935436 100644 --- a/Prepare-StorePackage.ps1 +++ b/Prepare-StorePackage.ps1 @@ -2,7 +2,7 @@ # Creates a single universal package for both Chrome Web Store and Edge Add-ons param( - [string]$Version = '1.1.0', + [string]$Version = '1.2.0', [string]$OutputPath = 'store-packages' ) @@ -16,127 +16,161 @@ if (!(Test-Path $OutputPath)) { # Determine source directory based on script location $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $sourceDir = $scriptDir # Script is in the root directory -$tempDir = Join-Path $env:TEMP 'check-extension-package' -Write-Host '📦 Preparing universal store package...' -ForegroundColor Yellow +$devFilesToRemove = @( + '*.md', + '*.log', + '.DS_Store', + 'Thumbs.db', + '*.tmp' +) -# Clean temp directory -if (Test-Path $tempDir) { - Remove-Item $tempDir -Recurse -Force +function Remove-DevelopmentFiles { + param( + [string]$TargetDir + ) + + foreach ($pattern in $devFilesToRemove) { + Get-ChildItem $TargetDir -Name $pattern -Recurse -Force 2>$null | ForEach-Object { + $fullPath = Join-Path $TargetDir $_ + if (Test-Path $fullPath) { + Remove-Item $fullPath -Force + Write-Host "Removed dev file: $_" -ForegroundColor Gray + } + } + } } -# Create temp directory -New-Item -ItemType Directory -Path $tempDir | Out-Null +function New-StorePackage { + param( + [string]$Title, + [string]$TempDirName, + [string[]]$FilesToInclude, + [string]$PackageName, + [switch]$RenameFirefoxManifest + ) -# Copy only the files needed for the extension -$filesToInclude = @( - 'manifest.json', - 'blocked.html', - 'config', - 'images', - 'options', - 'popup', - 'rules', - 'scripts', - 'styles' -) + $tempDir = Join-Path $env:TEMP $TempDirName + Write-Host "📦 Preparing $Title..." -ForegroundColor Yellow + + if (Test-Path $tempDir) { + Remove-Item $tempDir -Recurse -Force + } -foreach ($item in $filesToInclude) { - $sourcePath = Join-Path $sourceDir $item - if (Test-Path $sourcePath) { - $destPath = Join-Path $tempDir $item - if (Test-Path $sourcePath -PathType Container) { - Copy-Item $sourcePath $destPath -Recurse -Force + New-Item -ItemType Directory -Path $tempDir | Out-Null + + foreach ($item in $FilesToInclude) { + $sourcePath = Join-Path $sourceDir $item + if (Test-Path $sourcePath) { + $destPath = Join-Path $tempDir $item + if (Test-Path $sourcePath -PathType Container) { + Copy-Item $sourcePath $destPath -Recurse -Force + } else { + Copy-Item $sourcePath $destPath -Force + } + Write-Host "✅ Included: $item" -ForegroundColor Green } else { - Copy-Item $sourcePath $destPath -Force + Write-Host "⚠️ Not found: $item" -ForegroundColor Yellow } - Write-Host "✅ Included: $item" -ForegroundColor Green - } else { - Write-Host "⚠️ Not found: $item" -ForegroundColor Yellow } -} -# Remove any development/debug files from copied directories -$devFilesToRemove = @( - '*.md', - '*.log', - '.DS_Store', - 'Thumbs.db', - '*.tmp' -) + if ($RenameFirefoxManifest) { + $firefoxManifestPath = Join-Path $tempDir 'manifest.firefox.json' + $standardManifestPath = Join-Path $tempDir 'manifest.json' -foreach ($pattern in $devFilesToRemove) { - Get-ChildItem $tempDir -Name $pattern -Recurse -Force 2>$null | ForEach-Object { - $fullPath = Join-Path $tempDir $_ - if (Test-Path $fullPath) { - Remove-Item $fullPath -Force - Write-Host "Removed dev file: $_" -ForegroundColor Gray + if (Test-Path $firefoxManifestPath) { + if (Test-Path $standardManifestPath) { + Remove-Item $standardManifestPath -Force + } + Rename-Item -Path $firefoxManifestPath -NewName 'manifest.json' + Write-Host '✅ Renamed manifest.firefox.json to manifest.json' -ForegroundColor Green } } -} -# Update manifest.json for store -$manifestPath = Join-Path $tempDir 'manifest.json' -if (Test-Path $manifestPath) { - $manifest = Get-Content $manifestPath | ConvertFrom-Json + Remove-DevelopmentFiles -TargetDir $tempDir - # Update version - $manifest.version = $Version + $manifestPath = Join-Path $tempDir 'manifest.json' + if (Test-Path $manifestPath) { + $manifest = Get-Content $manifestPath | ConvertFrom-Json + $manifest.version = $Version + $manifest.content_security_policy = @{ + extension_pages = "script-src 'self'; object-src 'self'" + } - # Ensure production settings - $manifest.content_security_policy = @{ - extension_pages = "script-src 'self'; object-src 'self'" + $jsonString = $manifest | ConvertTo-Json -Depth 10 + $jsonString | Set-Content $manifestPath -Encoding UTF8 + Write-Host '✅ Updated manifest.json for store publishing' -ForegroundColor Green } - # Convert back to JSON with proper formatting - $jsonString = $manifest | ConvertTo-Json -Depth 10 - $jsonString | Set-Content $manifestPath -Encoding UTF8 + $optionsPath = Join-Path $tempDir 'options\options.js' + if (Test-Path $optionsPath) { + $content = Get-Content $optionsPath -Raw + $content = $content -replace 'const DEVELOPMENT_MODE = true', 'const DEVELOPMENT_MODE = false' + $content | Set-Content $optionsPath -Encoding UTF8 + Write-Host '✅ Disabled development mode in options.js' -ForegroundColor Green + } - Write-Host '✅ Updated manifest.json for stores' -ForegroundColor Green -} + $packagePath = Join-Path $OutputPath $PackageName + if (Test-Path $packagePath) { + Remove-Item $packagePath -Force + } -# Update options.js to disable development mode -$optionsPath = Join-Path $tempDir 'options\options.js' -if (Test-Path $optionsPath) { - $content = Get-Content $optionsPath -Raw - $content = $content -replace 'const DEVELOPMENT_MODE = true', 'const DEVELOPMENT_MODE = false' - $content | Set-Content $optionsPath -Encoding UTF8 - Write-Host '✅ Disabled development mode in options.js' -ForegroundColor Green -} + Compress-Archive -Path "$tempDir\*" -DestinationPath $packagePath + Remove-Item $tempDir -Recurse -Force -# Create the package -$packageName = "check-extension-v$Version.zip" -$packagePath = Join-Path $OutputPath $packageName + $size = [math]::Round((Get-Item $packagePath).Length / 1MB, 2) + Write-Host "✅ Created package: $PackageName ($size MB)" -ForegroundColor Green -# Remove existing package if it exists -if (Test-Path $packagePath) { - Remove-Item $packagePath -Force + return @{ + Name = $PackageName + Size = $size + } } -# Create the zip file -Compress-Archive -Path "$tempDir\*" -DestinationPath $packagePath -Write-Host "✅ Created package: $packageName" -ForegroundColor Green +$baseFilesToInclude = @( + 'blocked.html', + 'config', + 'images', + 'options', + 'popup', + 'rules', + 'scripts', + 'styles' +) + +$universalFilesToInclude = @('manifest.json') + $baseFilesToInclude +$firefoxFilesToInclude = @('manifest.firefox.json') + $baseFilesToInclude -# Clean up temp directory -Remove-Item $tempDir -Recurse -Force +$universalPackage = New-StorePackage ` + -Title 'universal Chrome/Edge package' ` + -TempDirName 'check-extension-package' ` + -FilesToInclude $universalFilesToInclude ` + -PackageName "check-extension-v$Version.zip" -# Get file size -$size = [math]::Round((Get-Item $packagePath).Length / 1MB, 2) +$firefoxPackage = New-StorePackage ` + -Title 'Firefox package' ` + -TempDirName 'check-extension-package-firefox' ` + -FilesToInclude $firefoxFilesToInclude ` + -PackageName "check-extension-firefox-v$Version.zip" ` + -RenameFirefoxManifest Write-Host '' -Write-Host '🎉 Universal store package created successfully!' -ForegroundColor Green +Write-Host '🎉 Store packages created successfully!' -ForegroundColor Green Write-Host "📁 Location: $OutputPath" -ForegroundColor Cyan -Write-Host " 📦 $packageName ($size MB)" -ForegroundColor White +Write-Host " 📦 $($universalPackage.Name) ($($universalPackage.Size) MB)" -ForegroundColor White +Write-Host " 🦊 $($firefoxPackage.Name) ($($firefoxPackage.Size) MB)" -ForegroundColor White Write-Host '' Write-Host '📋 Next Steps:' -ForegroundColor Yellow -Write-Host '1. Submit the SAME package to both stores:' -ForegroundColor White +Write-Host '1. Submit Chrome/Edge package to their stores:' -ForegroundColor White Write-Host ' 📤 Chrome Web Store: https://chrome.google.com/webstore/devconsole' -ForegroundColor Cyan Write-Host ' 📤 Edge Add-ons: https://partner.microsoft.com/dashboard/microsoftedge' -ForegroundColor Cyan -Write-Host '2. Note the assigned extension IDs from each store' -ForegroundColor White -Write-Host '3. Update enterprise registry files with store IDs:' -ForegroundColor White +Write-Host '2. Submit Firefox package to AMO:' -ForegroundColor White +Write-Host ' 🦊 Firefox Add-ons: https://addons.mozilla.org/developers/' -ForegroundColor Cyan +Write-Host '3. Note the assigned extension IDs from each store' -ForegroundColor White +Write-Host '4. Update enterprise registry files with store IDs:' -ForegroundColor White Write-Host ' .\Update-StoreIDs.ps1 -ChromeID -EdgeID ' -ForegroundColor Gray -Write-Host '4. Test managed policies with store-installed extensions' -ForegroundColor White +Write-Host '5. Test managed policies with store-installed extensions' -ForegroundColor White Write-Host '' -Write-Host '💡 Remember: Both stores accept the same ZIP file!' -ForegroundColor Yellow +Write-Host '💡 Remember: Firefox uses the dedicated Firefox ZIP from this script.' -ForegroundColor Yellow