Files
filtry_www/deploy-cloudflare.ps1
T
2026-09-18 19:34:06 +02:00

68 lines
2.0 KiB
PowerShell

param(
[string]$ProjectName,
[string]$AccountId
)
$ErrorActionPreference = "Stop"
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
$publishDirectory = Join-Path $root "wersja1"
$nodePath = "C:\Program Files\nodejs"
if ((Test-Path $nodePath) -and (($env:Path -split ";") -notcontains $nodePath)) {
$env:Path = "$nodePath;$env:Path"
}
if (-not (Test-Path (Join-Path $publishDirectory "index.html"))) {
throw "Folder wersja1 nie zawiera index.html."
}
# The repository root is the editing source; keep the Cloudflare bundle in sync.
$publishFiles = @("index.html", "styles.css", "app.js", "atut_baza.csv")
foreach ($file in $publishFiles) {
$source = Join-Path $root $file
$target = Join-Path $publishDirectory $file
if (-not (Test-Path $source)) {
throw "Brak pliku źródłowego: $source"
}
Copy-Item $source $target -Force
}
if (-not $ProjectName) {
$ProjectName = $env:CLOUDFLARE_PAGES_PROJECT
}
if (-not $ProjectName) {
$ProjectName = git -C $root config --local --get cloudflare.pagesProject
}
if (-not $AccountId) {
$AccountId = $env:CLOUDFLARE_ACCOUNT_ID
}
if (-not $AccountId) {
$AccountId = git -C $root config --local --get cloudflare.accountId
}
if (-not $ProjectName) {
throw "Podaj nazwe projektu Pages przez -ProjectName albo CLOUDFLARE_PAGES_PROJECT."
}
$deployArguments = @("pages", "deploy", $publishDirectory, "--project-name", $ProjectName)
if ($AccountId) {
$deployArguments += @("--account-id", $AccountId)
}
$wrangler = $null
$wranglerCommand = Get-Command wrangler.cmd -ErrorAction SilentlyContinue
if ($wranglerCommand) {
$wrangler = $wranglerCommand.Source
} else {
$userWrangler = Join-Path $env:APPDATA "npm\wrangler.cmd"
if (Test-Path $userWrangler) {
$wrangler = $userWrangler
}
}
if ($wrangler) {
& $wrangler @deployArguments
} elseif (Get-Command npx.cmd -ErrorAction SilentlyContinue) {
npx.cmd --yes wrangler @deployArguments
} else {
throw "Nie znaleziono Wrangler ani npx. Zainstaluj Node.js LTS i uruchom ponownie terminal."
}