fintechdarkpatterns / scripts /package-extension.ps1
yujisium's picture
Fintech Dark Patterns NLP Detector - full project upload
5752a28 verified
Raw
History Blame Contribute Delete
1.64 kB
$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"