diff --git a/.wrangler/cache/pages.json b/.wrangler/cache/pages.json new file mode 100644 index 0000000..661b59f --- /dev/null +++ b/.wrangler/cache/pages.json @@ -0,0 +1,4 @@ +{ + "account_id": "0a3818308d1764898fe0604506527911", + "project_name": "filtry" +} \ No newline at end of file diff --git a/.wrangler/cache/wrangler-account.json b/.wrangler/cache/wrangler-account.json new file mode 100644 index 0000000..cd305c0 --- /dev/null +++ b/.wrangler/cache/wrangler-account.json @@ -0,0 +1,6 @@ +{ + "account": { + "id": "0a3818308d1764898fe0604506527911", + "name": "Rapafun@gmail.com's Account" + } +} \ No newline at end of file diff --git a/deploy-cloudflare.ps1 b/deploy-cloudflare.ps1 new file mode 100644 index 0000000..a3ac9eb --- /dev/null +++ b/deploy-cloudflare.ps1 @@ -0,0 +1,56 @@ +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." +} + +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." +} diff --git a/hooks/post-push b/hooks/post-push new file mode 100644 index 0000000..eb7149a --- /dev/null +++ b/hooks/post-push @@ -0,0 +1,5 @@ +#!/bin/sh +set -e + +repo_root=$(git rev-parse --show-toplevel) +powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$repo_root/deploy-cloudflare.ps1" diff --git a/install-cloudflare-hook.ps1 b/install-cloudflare-hook.ps1 new file mode 100644 index 0000000..7a5d403 --- /dev/null +++ b/install-cloudflare-hook.ps1 @@ -0,0 +1,13 @@ +$ErrorActionPreference = "Stop" +$root = Split-Path -Parent $MyInvocation.MyCommand.Path +$hooks = Join-Path $root ".git\hooks" +$source = Join-Path $root "hooks\post-push" +$target = Join-Path $hooks "post-push" + +if (-not (Test-Path $hooks)) { + throw "Nie znaleziono folderu .git/hooks. Uruchom skrypt w katalogu repozytorium." +} + +Copy-Item $source $target -Force +Write-Host "Zainstalowano hook post-push: $target" +Write-Host "Po kazdym udanym git push zostanie uruchomiony deploy do Cloudflare Pages."