From 7692b1c9dd8fa5e226664e4d10d73e127e09efca Mon Sep 17 00:00:00 2001 From: Kaden Napper Date: Sun, 26 Jul 2026 14:14:05 +1000 Subject: [PATCH] build: add release script and ignore generated packages --- .gitignore | 2 + release.ps1 | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 release.ps1 diff --git a/.gitignore b/.gitignore index 314aa86..9c54374 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ build/ *.tmp *.temp *.log + +release/ diff --git a/release.ps1 b/release.ps1 new file mode 100644 index 0000000..66eb075 --- /dev/null +++ b/release.ps1 @@ -0,0 +1,124 @@ +# Hudra release builder +# Reads the version from manifest.json, creates a clean release folder, +# and produces a Chrome Web Store-ready ZIP. + +$ErrorActionPreference = "Stop" + +# Project locations +$ProjectRoot = $PSScriptRoot +$ManifestPath = Join-Path $ProjectRoot "manifest.json" +$ReleaseRoot = Join-Path $ProjectRoot "release" + +# Check that manifest.json exists +if (-not (Test-Path $ManifestPath)) { + Write-Host "ERROR: manifest.json was not found." -ForegroundColor Red + Write-Host "Place release.ps1 in the same folder as manifest.json." + exit 1 +} + +# Read extension name and version +try { + $Manifest = Get-Content $ManifestPath -Raw | ConvertFrom-Json +} +catch { + Write-Host "ERROR: manifest.json is not valid JSON." -ForegroundColor Red + exit 1 +} + +$ExtensionName = $Manifest.name +$Version = $Manifest.version + +if ([string]::IsNullOrWhiteSpace($ExtensionName)) { + $ExtensionName = "Hudra" +} + +if ([string]::IsNullOrWhiteSpace($Version)) { + Write-Host "ERROR: No version was found in manifest.json." -ForegroundColor Red + exit 1 +} + +$SafeName = $ExtensionName -replace '[^a-zA-Z0-9_-]', '-' +$ReleaseName = "$SafeName-v$Version" + +$StagingFolder = Join-Path $ReleaseRoot $ReleaseName +$ZipPath = Join-Path $ReleaseRoot "$ReleaseName.zip" + +Write-Host "" +Write-Host "Building $ExtensionName $Version..." -ForegroundColor Cyan +Write-Host "" + +# Files and folders that should not be included in the extension ZIP +$ExcludedItems = @( + ".git", + ".github", + ".gitea", + ".vscode", + "docs", + "release", + "node_modules", + ".gitignore", + "README.md", + "ROADMAP.md", + "CONTRIBUTING.md", + "LICENSE", + "release.ps1" +) + +# Recreate the staging folder +if (Test-Path $StagingFolder) { + Remove-Item $StagingFolder -Recurse -Force +} + +New-Item -ItemType Directory -Path $StagingFolder -Force | Out-Null + +# Copy extension files into the clean staging folder +Get-ChildItem -Path $ProjectRoot -Force | ForEach-Object { + if ($ExcludedItems -notcontains $_.Name) { + Copy-Item ` + -Path $_.FullName ` + -Destination $StagingFolder ` + -Recurse ` + -Force + } +} + +# Confirm that the copied release contains manifest.json +$CopiedManifest = Join-Path $StagingFolder "manifest.json" + +if (-not (Test-Path $CopiedManifest)) { + Write-Host "ERROR: manifest.json was not copied into the release folder." -ForegroundColor Red + exit 1 +} + +# Remove any previous ZIP for this version +if (Test-Path $ZipPath) { + Remove-Item $ZipPath -Force +} + +# ZIP the contents, ensuring manifest.json is at the ZIP root +$FilesToZip = Join-Path $StagingFolder "*" +Compress-Archive ` + -Path $FilesToZip ` + -DestinationPath $ZipPath ` + -CompressionLevel Optimal ` + -Force + +# Verify the ZIP was created +if (-not (Test-Path $ZipPath)) { + Write-Host "ERROR: The release ZIP could not be created." -ForegroundColor Red + exit 1 +} + +$ZipSize = [math]::Round((Get-Item $ZipPath).Length / 1KB, 1) + +Write-Host "Release created successfully!" -ForegroundColor Green +Write-Host "" +Write-Host "Release folder:" +Write-Host " $StagingFolder" -ForegroundColor Yellow +Write-Host "" +Write-Host "ZIP file:" +Write-Host " $ZipPath" -ForegroundColor Yellow +Write-Host "" +Write-Host "ZIP size: $ZipSize KB" +Write-Host "" +Write-Host "Ready for Gitea and the Chrome Web Store." -ForegroundColor Green \ No newline at end of file