build: add release script and ignore generated packages
This commit is contained in:
+124
@@ -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
|
||||
Reference in New Issue
Block a user