forked from CyberDrain/Check
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrepare-StorePackage.ps1
More file actions
176 lines (147 loc) · 6.33 KB
/
Prepare-StorePackage.ps1
File metadata and controls
176 lines (147 loc) · 6.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# Store Publication Preparation Script
# Creates a single universal package for both Chrome Web Store and Edge Add-ons
param(
[string]$Version = '1.2.0',
[string]$OutputPath = 'store-packages'
)
Write-Host '🏪 Universal Store Package Preparation' -ForegroundColor Cyan
# Create output directory
if (!(Test-Path $OutputPath)) {
New-Item -ItemType Directory -Path $OutputPath | Out-Null
}
# Determine source directory based on script location
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$sourceDir = $scriptDir # Script is in the root directory
$devFilesToRemove = @(
'*.md',
'*.log',
'.DS_Store',
'Thumbs.db',
'*.tmp'
)
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
}
}
}
}
function New-StorePackage {
param(
[string]$Title,
[string]$TempDirName,
[string[]]$FilesToInclude,
[string]$PackageName,
[switch]$RenameFirefoxManifest
)
$tempDir = Join-Path $env:TEMP $TempDirName
Write-Host "📦 Preparing $Title..." -ForegroundColor Yellow
if (Test-Path $tempDir) {
Remove-Item $tempDir -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 {
Write-Host "⚠️ Not found: $item" -ForegroundColor Yellow
}
}
if ($RenameFirefoxManifest) {
$firefoxManifestPath = Join-Path $tempDir 'manifest.firefox.json'
$standardManifestPath = Join-Path $tempDir 'manifest.json'
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
}
}
Remove-DevelopmentFiles -TargetDir $tempDir
$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'"
}
$jsonString = $manifest | ConvertTo-Json -Depth 10
$jsonString | Set-Content $manifestPath -Encoding UTF8
Write-Host '✅ Updated manifest.json for store publishing' -ForegroundColor Green
}
$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
}
$packagePath = Join-Path $OutputPath $PackageName
if (Test-Path $packagePath) {
Remove-Item $packagePath -Force
}
Compress-Archive -Path "$tempDir\*" -DestinationPath $packagePath
Remove-Item $tempDir -Recurse -Force
$size = [math]::Round((Get-Item $packagePath).Length / 1MB, 2)
Write-Host "✅ Created package: $PackageName ($size MB)" -ForegroundColor Green
return @{
Name = $PackageName
Size = $size
}
}
$baseFilesToInclude = @(
'blocked.html',
'config',
'images',
'options',
'popup',
'rules',
'scripts',
'styles'
)
$universalFilesToInclude = @('manifest.json') + $baseFilesToInclude
$firefoxFilesToInclude = @('manifest.firefox.json') + $baseFilesToInclude
$universalPackage = New-StorePackage `
-Title 'universal Chrome/Edge package' `
-TempDirName 'check-extension-package' `
-FilesToInclude $universalFilesToInclude `
-PackageName "check-extension-v$Version.zip"
$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 '🎉 Store packages created successfully!' -ForegroundColor Green
Write-Host "📁 Location: $OutputPath" -ForegroundColor Cyan
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 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. 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
Write-Host '5. Test managed policies with store-installed extensions' -ForegroundColor White
Write-Host ''
Write-Host '💡 Remember: Firefox uses the dedicated Firefox ZIP from this script.' -ForegroundColor Yellow