57 lines
1.6 KiB
PowerShell
57 lines
1.6 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."
|
|
}
|
|
|
|
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."
|
|
}
|