zscripts-token-savers/ZKillOnly.ps1
KellyMichels 502c0e8b29 feat(zversion, zrelease): toolkit versioning + downloadable release zips
Implements the versioning rule (SmartPlant's 5-segment scheme, now the global
standard; currently only sp and zscripts are on it at v1.x):

    v{major}.{rc}.{beta}.{alpha}.{build}

zversion: get / bump / bump-stage / set. A stage bump zeroes every lower
segment including build. 'bump' is one per PR and one per defect fix, not per
file. Any write rewrites three things together, because they are only useful
when they agree: build-version.json (source of truth), a '# Version:' line in
all 42 script headers (a lone copied script still says which release it came
from), and CHECKSUMS.txt (stamping changes every file).

zrelease: packages the current version as releases/zscripts-<version>.zip with
a sibling .sha256, for people who want the toolkit without cloning. One hash
verifies the download; the bundled CHECKSUMS.txt verifies the extracted
contents. Refuses to overwrite an existing version's zip (released = immutable;
bump instead), and refuses to package when zchecksums fails. tests/ excluded
from the zip; releases/ never packages itself.

First release included: releases/zscripts-v1.0.0.0.0.zip (42 scripts + 7
support files) and its .sha256.

.gitattributes: releases/*.sha256 pinned LF (sha256sum treats a trailing CR as
part of the filename), releases/*.zip marked binary.

Verified end-to-end as a downloader would experience it, in WSL: sha256sum -c
on the zip passes, unzip, sha256sum -c CHECKSUMS.txt inside gives 42 OK / 0
FAILED, and the extracted zdeploy.ps1 header and build-version.json both read
v1.0.0.0.0. Double-release guard and -Verify mode exercised. Full Pester suite
219/219 (the checksum tests absorb the new files automatically).
2026-07-28 13:27:50 -05:00

79 lines
2.7 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.
# Version: v1.0.0.0.0
# ZKillOnly.ps1 — stop local dev server listeners for any project in zconfig.json.
#
# Usage:
# zkill <project> [<project> ...] [-Port N] [-KillAll]
#
# Examples:
# zkill viteapp
# zkill pyapp nextapp
# zkill nextapp -KillAll # also kill stray node/python processes referencing the project
#
param(
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[string[]]$Projects = @(),
[Alias("p")][int]$Port = 0,
[switch]$KillAll
)
$ErrorActionPreference = "Stop"
. (Join-Path $PSScriptRoot "ZHelpers.ps1")
Start-ZTracking
if ($Projects.Count -eq 0) {
$keys = (Get-ZProjectKeys) -join ', '
Write-Host ""
Write-Host "Usage: zkill <project> [<project> ...] | all [-Port N] [-KillAll]" -ForegroundColor Yellow
Write-Host " Projects in zconfig.json: $keys" -ForegroundColor Gray
Write-Host " 'all' stops the dev server of every project that has one." -ForegroundColor Gray
Stop-ZTracking; exit 1
}
# Tolerate switch-style args (zkill -myproject) from muscle memory.
$Projects = @($Projects | ForEach-Object { $_.TrimStart('-') })
# 'all' -> every project that actually has a local dev server (a ports.dev).
if ($Projects -contains 'all') {
$cfg = Get-ZConfig
$Projects = @(Get-ZProjectKeys | Where-Object { $cfg.projects.$_.ports -and $cfg.projects.$_.ports.dev })
if ($Projects.Count -eq 0) {
Write-Host "No projects have a dev port to kill." -ForegroundColor Yellow
Stop-ZTracking; exit 0
}
Write-Host "Killing dev servers for: $($Projects -join ', ')" -ForegroundColor Cyan
}
foreach ($key in $Projects) {
$proj = Get-ZProject -Key $key
$devPort = if ($Port -gt 0) { $Port } elseif ($proj.ports -and $proj.ports.dev) { [int]$proj.ports.dev } else { 0 }
Write-Host ""
Write-Host "=== zkill ($($proj.label)) ===" -ForegroundColor Cyan
$killed = 0
if ($devPort -gt 0) {
Write-Host "Port: $devPort" -ForegroundColor DarkGray
$killed += Stop-ListenersOnPort -Port $devPort
} else {
Write-Host "No dev port configured for '$key' - skipping port kill." -ForegroundColor DarkYellow
}
if ($KillAll -and $proj.localRoot) {
$killed += Stop-ProjectProcesses -ProjectRoot $proj.localRoot
}
if ($killed -gt 0) {
Write-Host " $killed process(es) stopped" -ForegroundColor Magenta
} else {
Write-Host " Nothing to kill" -ForegroundColor Green
}
}
Write-Host ""
Write-Host "Kill complete." -ForegroundColor Cyan
Stop-ZTracking