|
| 1 | +param( |
| 2 | + [string]$OutputDir = ".release" |
| 3 | +) |
| 4 | + |
| 5 | +$ErrorActionPreference = "Stop" |
| 6 | + |
| 7 | +if (-not (Test-Path "package.json")) { |
| 8 | + throw "Run this script from repository root." |
| 9 | +} |
| 10 | + |
| 11 | +$packageJson = Get-Content -Raw "package.json" | ConvertFrom-Json |
| 12 | +$version = [string]$packageJson.version |
| 13 | +if ([string]::IsNullOrWhiteSpace($version)) { |
| 14 | + throw "Could not resolve version from package.json" |
| 15 | +} |
| 16 | + |
| 17 | +$packageName = "Web2Comics-TelegramBot-v$version" |
| 18 | +$stagingRoot = Join-Path $OutputDir $packageName |
| 19 | +$zipPath = Join-Path $OutputDir "$packageName-deploy.zip" |
| 20 | + |
| 21 | +if (Test-Path $stagingRoot) { |
| 22 | + Remove-Item $stagingRoot -Recurse -Force |
| 23 | +} |
| 24 | +if (Test-Path $zipPath) { |
| 25 | + Remove-Item $zipPath -Force |
| 26 | +} |
| 27 | +if (-not (Test-Path $OutputDir)) { |
| 28 | + New-Item -ItemType Directory -Path $OutputDir | Out-Null |
| 29 | +} |
| 30 | +New-Item -ItemType Directory -Path $stagingRoot | Out-Null |
| 31 | + |
| 32 | +# Required runtime/deploy content for standalone bot deployment. |
| 33 | +$includePaths = @( |
| 34 | + "telegram", |
| 35 | + "engine", |
| 36 | + "docker", |
| 37 | + "render", |
| 38 | + "scripts/deploy-bot-auto.js", |
| 39 | + "scripts/validate-secrets.js", |
| 40 | + "scripts/cloudflare/create-scoped-tokens.js", |
| 41 | + "package.json", |
| 42 | + "package-lock.json", |
| 43 | + "README.md" |
| 44 | +) |
| 45 | + |
| 46 | +foreach ($entry in $includePaths) { |
| 47 | + if (-not (Test-Path $entry)) { continue } |
| 48 | + $destination = Join-Path $stagingRoot $entry |
| 49 | + $destDir = Split-Path -Parent $destination |
| 50 | + if (-not (Test-Path $destDir)) { |
| 51 | + New-Item -ItemType Directory -Path $destDir -Force | Out-Null |
| 52 | + } |
| 53 | + if ((Get-Item $entry).PSIsContainer) { |
| 54 | + Copy-Item $entry -Destination $destination -Recurse -Force |
| 55 | + } else { |
| 56 | + Copy-Item $entry -Destination $destination -Force |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +# Remove secrets and transient artifacts aggressively. |
| 61 | +$removePaths = @( |
| 62 | + ".env", |
| 63 | + ".env.local", |
| 64 | + ".env.e2e.local", |
| 65 | + ".telegram.yaml", |
| 66 | + ".cloudflare.yaml", |
| 67 | + ".aws.yaml", |
| 68 | + "telegram/.env", |
| 69 | + "telegram/out", |
| 70 | + "telegram/data", |
| 71 | + "telegram/cfgs", |
| 72 | + "cloudflare/.dev.vars", |
| 73 | + "cloudflare/.wrangler", |
| 74 | + ".wrangler", |
| 75 | + "node_modules" |
| 76 | +) |
| 77 | +foreach ($rel in $removePaths) { |
| 78 | + $p = Join-Path $stagingRoot $rel |
| 79 | + if (Test-Path $p) { |
| 80 | + Remove-Item $p -Recurse -Force -ErrorAction SilentlyContinue |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +# Remove any accidentally copied secret-like files. |
| 85 | +Get-ChildItem -Path $stagingRoot -Recurse -File -ErrorAction SilentlyContinue | |
| 86 | + Where-Object { |
| 87 | + $_.Name -match '(^|\.)(env|yaml|yml)$' -and |
| 88 | + ($_.FullName -match 'telegram\\\.env$' -or $_.Name -match '^\.(telegram|cloudflare|aws)\.ya?ml$' -or $_.Name -match '^\.env') |
| 89 | + } | |
| 90 | + ForEach-Object { Remove-Item $_.FullName -Force -ErrorAction SilentlyContinue } |
| 91 | + |
| 92 | +Compress-Archive -Path $stagingRoot -DestinationPath $zipPath -CompressionLevel Optimal -Force |
| 93 | + |
| 94 | +$zipItem = Get-Item $zipPath |
| 95 | +Write-Output "Created: $($zipItem.FullName)" |
| 96 | +Write-Output "Size: $([Math]::Round($zipItem.Length / 1MB, 2)) MB" |
| 97 | +Write-Output "Package root: $stagingRoot" |
0 commit comments