File size: 1,642 Bytes
5752a28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
$ErrorActionPreference = "Stop"

$projectRoot = Split-Path -Parent $PSScriptRoot
$extensionDir = Join-Path $projectRoot "extension"
$artifactsDir = Join-Path $projectRoot "artifacts"
$unpackedDir = Join-Path $artifactsDir "dark-pattern-nlp-auditor-unpacked"
$outputPath = Join-Path $artifactsDir "dark-pattern-nlp-auditor-extension.zip"

if (-not (Test-Path -LiteralPath $extensionDir)) {
    throw "Extension directory not found: $extensionDir"
}

New-Item -ItemType Directory -Path $artifactsDir -Force | Out-Null

$artifactsFullPath = [System.IO.Path]::GetFullPath($artifactsDir).TrimEnd("\") + "\"
$unpackedFullPath = [System.IO.Path]::GetFullPath($unpackedDir)
if (-not $unpackedFullPath.StartsWith($artifactsFullPath, [System.StringComparison]::OrdinalIgnoreCase)) {
    throw "Refusing to replace unpacked directory outside artifacts: $unpackedFullPath"
}

if (Test-Path -LiteralPath $unpackedDir) {
    Remove-Item -LiteralPath $unpackedDir -Recurse -Force
}

New-Item -ItemType Directory -Path $unpackedDir -Force | Out-Null
Copy-Item -Path (Join-Path $extensionDir "*") -Destination $unpackedDir -Recurse -Force

$manifestPath = Join-Path $unpackedDir "manifest.json"
if (-not (Test-Path -LiteralPath $manifestPath)) {
    throw "Packaged extension is missing manifest.json: $manifestPath"
}

Get-Content -Raw -LiteralPath $manifestPath | ConvertFrom-Json | Out-Null

if (Test-Path -LiteralPath $outputPath) {
    Remove-Item -LiteralPath $outputPath -Force
}

Compress-Archive -Path (Join-Path $unpackedDir "*") -DestinationPath $outputPath
Write-Output "Load unpacked folder: $unpackedDir"
Write-Output "ZIP package: $outputPath"