-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.ps1
More file actions
67 lines (59 loc) · 2.75 KB
/
Copy pathpackage.ps1
File metadata and controls
67 lines (59 loc) · 2.75 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
# Package the extension for Chrome Web Store upload.
# Reads the version from manifest.json and writes:
# dist\bookmark-icon-customizer-v<version>.zip
# Only runtime files are included (no node_modules, docs, scratch, dev
# scripts, .git, etc.). Re-run any time after editing sources or bumping
# the version in manifest.json — the matching-version zip is overwritten;
# older-version zips in dist\ are left in place as archive copies.
$ErrorActionPreference = 'Stop'
Set-Location -LiteralPath $PSScriptRoot
$manifest = Get-Content 'manifest.json' -Raw | ConvertFrom-Json
$version = $manifest.version
if (-not $version) { throw 'No version field in manifest.json' }
# Allowlist of runtime files/dirs. Anything not listed here (node_modules,
# docs, scratch, dist, .git, .gitignore, README, PRIVACY, PROMOTION_POSTS,
# generate_icons.js, resize_icons.js, package.json, package-lock.json,
# package.bat, package.ps1, .claude) is excluded from the zip.
$items = @(
'manifest.json',
'background.js',
'content_script.js',
'popup.html',
'popup.css',
'popup.js',
'launcher.html',
'launcher.js',
'sandbox.html',
'icons',
'lib'
)
foreach ($i in $items) {
if (-not (Test-Path -LiteralPath $i)) { throw "Missing required file: $i" }
}
# Safety net: never ship a debug build. lib/debug.js gates all diagnostic
# console.log output behind BIC_DEBUG; if it's still true here, somebody
# (often me) forgot to flip it back after a debugging session.
if (Get-Content 'lib/debug.js' -Raw | Select-String -Pattern 'BIC_DEBUG\s*=\s*true' -Quiet) {
throw "lib/debug.js has BIC_DEBUG=true. Flip it to false before packaging for release."
}
if (-not (Test-Path 'dist')) { New-Item -ItemType Directory -Path 'dist' | Out-Null }
$output = Join-Path 'dist' "bookmark-icon-customizer-v$version.zip"
if (Test-Path -LiteralPath $output) { Remove-Item -LiteralPath $output -Force }
# Stage to a temp dir before zipping. Compress-Archive opens source files
# with exclusive read locks, which transiently conflicts with Dropbox sync,
# antivirus scans, and IDEs that hold manifest.json open — copying first
# breaks the contention so packaging always succeeds.
$staging = Join-Path $env:TEMP "bic-pkg-$([guid]::NewGuid().ToString('N'))"
New-Item -ItemType Directory -Path $staging | Out-Null
try {
Write-Host "Packaging v$version..."
foreach ($i in $items) {
Copy-Item -LiteralPath $i -Destination $staging -Recurse -Force
}
$stagedItems = Get-ChildItem -LiteralPath $staging | ForEach-Object { $_.FullName }
Compress-Archive -Path $stagedItems -DestinationPath $output -Force
$sizeKB = [math]::Round((Get-Item -LiteralPath $output).Length / 1KB, 1)
Write-Host "Done: $output ($sizeKB KB)"
} finally {
Remove-Item -LiteralPath $staging -Recurse -Force -ErrorAction SilentlyContinue
}