/ create-xpi.ps1
create-xpi.ps1
 1  # PowerShell script to build XPI file for Mnemonic Firefox extension
 2  $ErrorActionPreference = "Stop"
 3  
 4  $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
 5  $SourceDir = Join-Path $ScriptDir ".output\firefox-mv3"
 6  $ZipFile = Join-Path $ScriptDir ".output\mnemonic.zip"
 7  $OutputFile = Join-Path $ScriptDir ".output\mnemonic.xpi"
 8  
 9  # Remove old files if exist
10  if (Test-Path $OutputFile) {
11      Remove-Item $OutputFile -Force
12      Write-Host "Removed existing XPI file"
13  }
14  if (Test-Path $ZipFile) {
15      Remove-Item $ZipFile -Force
16  }
17  
18  Write-Host "Creating XPI file..."
19  
20  Add-Type -AssemblyName System.IO.Compression.FileSystem
21  
22  try {
23      # Create new ZIP archive
24      $zip = [System.IO.Compression.ZipFile]::Open($ZipFile, 'Create')
25  
26      # Get all files recursively
27      Get-ChildItem -Path $SourceDir -Recurse -File | ForEach-Object {
28          $fullPath = $_.FullName
29          $relativePath = $_.FullName.Substring($SourceDir.Length + 1) -replace '\\', '/'
30          Write-Host "  Adding: $relativePath"
31          [System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip, $fullPath, $relativePath) | Out-Null
32      }
33  
34      $zip.Dispose()
35  
36      # Rename .zip to .xpi
37      Move-Item -Path $ZipFile -Destination $OutputFile -Force
38  
39      if (Test-Path $OutputFile) {
40          $fileInfo = Get-Item $OutputFile
41          Write-Host ""
42          Write-Host "Success! XPI file created: $OutputFile" -ForegroundColor Green
43          Write-Host "File size: $($fileInfo.Length) bytes"
44      } else {
45          Write-Host "Error: Failed to create XPI file" -ForegroundColor Red
46      }
47  }
48  catch {
49      Write-Host "Error: $_" -ForegroundColor Red
50      if ($zip) { $zip.Dispose() }
51  }