Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
210 changes: 122 additions & 88 deletions Prepare-StorePackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Creates a single universal package for both Chrome Web Store and Edge Add-ons
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Header comment says this script "Creates a single universal package for both Chrome Web Store and Edge Add-ons", but the script now also builds a separate Firefox ZIP. Update the header comment to match the current behavior so the script’s purpose is accurate.

Suggested change
# Creates a single universal package for both Chrome Web Store and Edge Add-ons
# Creates a universal package for Chrome Web Store and Edge Add-ons, plus a separate Firefox ZIP

Copilot uses AI. Check for mistakes.

param(
[string]$Version = '1.1.0',
[string]$Version = '1.2.0',
[string]$OutputPath = 'store-packages'
)

Expand All @@ -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
Comment on lines +34 to +38
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get-ChildItem $TargetDir -Name $pattern -Recurse does not filter by $pattern (the -Name switch is being given an argument), so this will enumerate essentially all items under $TargetDir. As a result, the loop can end up deleting most of the package contents. Use -Filter $pattern (or -Include $pattern with -File) and avoid passing a value to -Name (or drop -Name entirely and use .FullName).

Suggested change
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
Get-ChildItem -Path $TargetDir -Filter $pattern -Recurse -Force -File 2>$null | ForEach-Object {
if (Test-Path $_.FullName) {
Remove-Item $_.FullName -Force
Write-Host "Removed dev file: $($_.FullName)" -ForegroundColor Gray

Copilot uses AI. Check for mistakes.
}
}
}
}

# 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'"
Comment on lines +94 to +97
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script overwrites manifest.content_security_policy with script-src 'self'; object-src 'self', but the checked-in manifests allow Google Fonts (fonts.googleapis.com/fonts.gstatic.com) and style-src 'unsafe-inline', and extension pages (e.g., popup/options/blocked) reference those resources. This packaging step will likely break UI rendering in the store builds unless the pages are updated to self-host assets or the CSP merge preserves the required directives.

Suggested change
$manifest = Get-Content $manifestPath | ConvertFrom-Json
$manifest.version = $Version
$manifest.content_security_policy = @{
extension_pages = "script-src 'self'; object-src 'self'"
$manifest = Get-Content $manifestPath -Raw | ConvertFrom-Json
$manifest.version = $Version
if ($null -eq $manifest.content_security_policy) {
$manifest.content_security_policy = @{
extension_pages = "script-src 'self'; object-src 'self'"
}

Copilot uses AI. Check for mistakes.
}

# 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
Comment on lines +108 to +110
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script attempts to disable development mode by replacing const DEVELOPMENT_MODE = true, but options/options.js does not contain that string, so this will not change anything while still logging success. Consider either removing this step, updating it to match the current mechanism, or validating that the replacement actually occurred before writing the "Disabled development mode" message.

Suggested change
$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
$developmentModeEnabled = 'const DEVELOPMENT_MODE = true'
$developmentModeDisabled = 'const DEVELOPMENT_MODE = false'
if ($content.Contains($developmentModeEnabled)) {
$content = $content.Replace($developmentModeEnabled, $developmentModeDisabled)
$content | Set-Content $optionsPath -Encoding UTF8
Write-Host '✅ Disabled development mode in options.js' -ForegroundColor Green
} else {
Write-Host '⚠️ Could not find development mode flag in options.js; no changes made' -ForegroundColor Yellow
}

Copilot uses AI. Check for mistakes.
}

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
Comment on lines +118 to +122
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Compress-Archive fails, the script still removes $tempDir and then calls Get-Item $packagePath, which will throw and also removes the build artifacts needed for debugging. Consider using -ErrorAction Stop plus try/catch/finally so cleanup happens reliably, but only after you’ve confirmed the archive was created (and report a clear error when it isn’t).

Copilot uses AI. Check for mistakes.

# 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 <chrome-id> -EdgeID <edge-id>' -ForegroundColor Gray
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usage hint for Update-StoreIDs.ps1 uses parameter names -ChromeID / -EdgeID, but Update-StoreIDs.ps1 defines -ChromeExtensionId / -EdgeExtensionId (and -FirefoxExtensionId). Update this line so users can copy/paste a working command.

Suggested change
Write-Host ' .\Update-StoreIDs.ps1 -ChromeID <chrome-id> -EdgeID <edge-id>' -ForegroundColor Gray
Write-Host ' .\Update-StoreIDs.ps1 -ChromeExtensionId <chrome-id> -EdgeExtensionId <edge-id> -FirefoxExtensionId <firefox-id>' -ForegroundColor Gray

Copilot uses AI. Check for mistakes.
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
Loading