refactor(createzip): change the name from release to createZip
This commit is contained in:
103
scripts/createZip.ps1
Normal file
103
scripts/createZip.ps1
Normal file
@@ -0,0 +1,103 @@
|
||||
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$rootDir = Join-Path $scriptDir ".."
|
||||
$packageJsonPath = Join-Path $rootDir "package.json"
|
||||
$env:GOOS = "windows"
|
||||
$env:GOARCH = "amd64"
|
||||
$keepReleases = 10
|
||||
|
||||
function Get-PackageVersion {
|
||||
param (
|
||||
[string]$packageJsonPath
|
||||
)
|
||||
|
||||
if (-not (Test-Path $packageJsonPath)) {
|
||||
Write-Warning "package.json not found at $packageJsonPath"
|
||||
return $null
|
||||
}
|
||||
|
||||
$jsonContent = Get-Content $packageJsonPath -Raw
|
||||
try {
|
||||
$json = $jsonContent | ConvertFrom-Json
|
||||
return $json.version
|
||||
}
|
||||
catch {
|
||||
Write-Warning "Failed to parse package.json: $_"
|
||||
return $null
|
||||
}
|
||||
}
|
||||
|
||||
$version = Get-PackageVersion -packageJsonPath $packageJsonPath
|
||||
Write-Host "Project version from package.json is: $version"
|
||||
$buildNumberFile = Join-Path $rootDir "BUILD_NUMBER"
|
||||
|
||||
if (Test-Path $buildNumberFile) {
|
||||
$buildNumber = Get-Content $buildNumberFile -Raw
|
||||
$buildNumber = $buildNumber.Trim()
|
||||
Write-Host "Current build number: $buildNumber"
|
||||
} else {
|
||||
Write-Warning "BUILD_NUMBER file not found at $buildNumberFile"
|
||||
}
|
||||
|
||||
$releaseFolder = Join-Path $rootDir "releases"
|
||||
$zipName = "release-v$version-$buildNumber.zip"
|
||||
$zipPath = Join-Path $releaseFolder $zipName
|
||||
|
||||
|
||||
if (-not (Test-Path $releaseFolder)) {
|
||||
New-Item -ItemType Directory -Path $releaseFolder | Out-Null
|
||||
}
|
||||
|
||||
# Remove zip if it already exists
|
||||
if (Test-Path $zipPath) {
|
||||
Write-Host "Removing existing zip: $zipPath"
|
||||
Remove-Item $zipPath -Force
|
||||
}
|
||||
|
||||
# Clean up older release files (keep only newest X)
|
||||
$existingZips = Get-ChildItem -Path $releaseFolder -Filter "release-*.zip" | Sort-Object LastWriteTime -Descending
|
||||
|
||||
if ($existingZips.Count -gt $keepReleases) {
|
||||
$toRemove = $existingZips | Select-Object -Skip $keepReleases
|
||||
foreach ($file in $toRemove) {
|
||||
Write-Host "Deleting old release: $($file.Name)"
|
||||
Remove-Item $file.FullName -Force
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "`nPackaging release: $($zipName)"
|
||||
|
||||
# Create a temporary staging directory
|
||||
$tempStageDir = New-Item -ItemType Directory -Path (Join-Path $env:TEMP "lst_staging") -Force
|
||||
|
||||
# Copy files to organized structure
|
||||
$filesToCopy = @(
|
||||
@{ Source = "backend\lst_backend.exe"; Destination = "backend\lst_backend.exe" },
|
||||
@{ Source = "LstWrapper\publish"; Destination = "lstwrapper\" },
|
||||
@{ Source = "frontend\.nitro"; Destination = "frontend\.nitro" },
|
||||
@{ Source = "frontend\.tanstack"; Destination = "frontend\.tanstack" },
|
||||
@{ Source = "frontend\.output"; Destination = "frontend\.output" },
|
||||
@{ Source = "frontend\public"; Destination = "frontend\public" },
|
||||
@{ Source = "package.json"; Destination = "package.json" },
|
||||
@{ Source = "CHANGELOG.md"; Destination = "CHANGELOG.md" },
|
||||
@{ Source = "README.md"; Destination = "README.md" }
|
||||
)
|
||||
|
||||
foreach ($file in $filesToCopy) {
|
||||
$destPath = Join-Path $tempStageDir $file.Destination
|
||||
New-Item -ItemType Directory -Path (Split-Path $destPath -Parent) -Force | Out-Null
|
||||
Copy-Item -Path $file.Source -Destination $destPath -Recurse -Force
|
||||
}
|
||||
|
||||
# Create the zip from the staged directory
|
||||
Compress-Archive -Path "$tempStageDir\*" -DestinationPath $zipPath
|
||||
|
||||
# Clean up temporary directory
|
||||
Remove-Item $tempStageDir -Recurse -Force
|
||||
|
||||
Write-Host "`nRelease package created at: $($zipPath)"
|
||||
Write-Host "Organized structure:"
|
||||
Write-Host "- backend/"
|
||||
Write-Host "- frontend/"
|
||||
Write-Host "- lstwrapper/"
|
||||
Write-Host "- CHANGELOG.md"
|
||||
Write-Host "- README.md"
|
||||
Reference in New Issue
Block a user