-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpackage-extension.ps1
More file actions
51 lines (43 loc) · 2.44 KB
/
Copy pathpackage-extension.ps1
File metadata and controls
51 lines (43 loc) · 2.44 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
# Package the ExecEndpoints Chrome extension into a Chrome Web Store .zip.
# Usage: powershell -ExecutionPolicy Bypass -File package-extension.ps1
# Produces dist\ExecEndpoints-<version>.zip (manifest.json at the zip root).
$ErrorActionPreference = "Stop"
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
$ext = Join-Path $root "extension"
$dist = Join-Path $root "dist"
if (-not (Test-Path (Join-Path $ext "manifest.json"))) {
throw "extension\manifest.json not found next to this script."
}
# version from the manifest (Web Store requires this to increase each upload)
$manifest = Get-Content (Join-Path $ext "manifest.json") -Raw | ConvertFrom-Json
$version = $manifest.version
if (-not $version) { throw "No version in manifest.json." }
New-Item -ItemType Directory -Force -Path $dist | Out-Null
$zip = Join-Path $dist ("ExecEndpoints-" + $version + ".zip")
if (Test-Path $zip) { Remove-Item $zip -Force }
# stage a clean copy so dev-only files never ship
$stage = Join-Path $env:TEMP ("ee_pkg_" + [guid]::NewGuid().ToString("N"))
New-Item -ItemType Directory -Force -Path $stage | Out-Null
Copy-Item (Join-Path $ext "*") $stage -Recurse -Force
# drop dev-only helpers / junk from the staged copy
$drop = Get-ChildItem $stage -Recurse -Force -Include "make_icon.py","__pycache__",".DS_Store","Thumbs.db" -ErrorAction SilentlyContinue
foreach ($d in $drop) { Remove-Item $d.FullName -Recurse -Force -ErrorAction SilentlyContinue }
# zip the CONTENTS of the staged folder with FORWARD-SLASH entry names (Web-Store-safe;
# Windows Compress-Archive writes backslashes, which some tooling rejects).
Add-Type -AssemblyName System.IO.Compression | Out-Null
Add-Type -AssemblyName System.IO.Compression.FileSystem | Out-Null
$fs = [System.IO.File]::Open($zip, [System.IO.FileMode]::Create)
$archive = New-Object System.IO.Compression.ZipArchive($fs, [System.IO.Compression.ZipArchiveMode]::Create)
try {
Get-ChildItem $stage -Recurse -File | ForEach-Object {
$rel = $_.FullName.Substring($stage.Length + 1).Replace('\', '/')
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($archive, $_.FullName, $rel) | Out-Null
}
} finally {
$archive.Dispose(); $fs.Dispose()
}
Remove-Item $stage -Recurse -Force
$size = "{0:N0} KB" -f ((Get-Item $zip).Length / 1KB)
Write-Host ""
Write-Host "Packaged ExecEndpoints v$version -> $zip ($size)" -ForegroundColor Green
Write-Host "Upload it at https://chrome.google.com/webstore/devconsole" -ForegroundColor DarkGray