mirror of
https://github.com/kellymichels/zscripts-token-savers
synced 2026-10-07 07:18:18 +00:00
Config-driven PowerShell scripts to run infrastructure tasks (deploy, restart, backup, diagnostics) yourself instead of having an AI agent orchestrate them, to save agent tokens. Environment specifics live in zconfig.json (gitignored).
66 lines
2.3 KiB
PowerShell
66 lines
2.3 KiB
PowerShell
# Evomedia.net Token Savers — https://github.com/kellymichels/zscripts-token-savers
|
|
# Created by Kelly Michels · dev@evomedia.net
|
|
# Licensed under the MIT License. See LICENSE.
|
|
|
|
# ZKiller.ps1 — kill then restart dev servers for any project in zconfig.json.
|
|
#
|
|
# Usage:
|
|
# zrestart <project> [<project> ...] [-Port N] [-KillAll] [-NoRestart] [-Detached] [-BindHost host]
|
|
#
|
|
# Examples:
|
|
# zrestart viteapp
|
|
# zrestart pyapp -Detached
|
|
#
|
|
param(
|
|
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
|
|
[string[]]$Projects = @(),
|
|
[Alias("p")][int]$Port = 0,
|
|
[switch]$KillAll,
|
|
[switch]$NoRestart,
|
|
[switch]$Detached,
|
|
[string]$BindHost = "127.0.0.1"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
. (Join-Path $PSScriptRoot "ZHelpers.ps1")
|
|
Start-ZTracking
|
|
|
|
$KillScript = Join-Path $PSScriptRoot "ZKillOnly.ps1"
|
|
$StartScript = Join-Path $PSScriptRoot "zstart.ps1"
|
|
|
|
if ($Projects.Count -eq 0) {
|
|
$keys = (Get-ZProjectKeys) -join ', '
|
|
Write-Host ""
|
|
Write-Host "Usage: zrestart <project> [<project> ...] [-Port N] [-KillAll] [-NoRestart] [-Detached] [-BindHost host]" -ForegroundColor Yellow
|
|
Write-Host " Projects in zconfig.json: $keys" -ForegroundColor Gray
|
|
Stop-ZTracking; exit 1
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "=== zrestart ===" -ForegroundColor Cyan
|
|
|
|
foreach ($key in $Projects) {
|
|
Write-Host "--- $key ---" -ForegroundColor DarkCyan
|
|
|
|
# Splat named params via a hashtable, not an array. The target scripts bind
|
|
# $Projects with ValueFromRemainingArguments (greedy), which swallows an
|
|
# array-splatted "-Detached"/"-KillAll" string as a literal project value
|
|
# instead of binding the switch. Hashtable splatting binds switches reliably.
|
|
$killParams = @{}
|
|
if ($Port -gt 0) { $killParams.Port = $Port }
|
|
if ($KillAll) { $killParams.KillAll = $true }
|
|
& $KillScript $key @killParams
|
|
if ($LASTEXITCODE -ne 0) { Stop-ZTracking; exit $LASTEXITCODE }
|
|
|
|
if (-not $NoRestart) {
|
|
Start-Sleep -Seconds 1
|
|
$startParams = @{}
|
|
if ($Port -gt 0) { $startParams.Port = $Port }
|
|
if ($BindHost -ne "127.0.0.1") { $startParams.BindHost = $BindHost }
|
|
if ($Detached) { $startParams.Detached = $true }
|
|
& $StartScript $key @startParams
|
|
if ($LASTEXITCODE -ne 0) { Stop-ZTracking; exit $LASTEXITCODE }
|
|
}
|
|
}
|
|
Stop-ZTracking
|