@tapi-dev/sdk 0.1.32 → 0.1.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +12 -59
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2436,54 +2436,9 @@ async function isPortAvailable(port) {
|
|
|
2436
2436
|
});
|
|
2437
2437
|
}
|
|
2438
2438
|
async function reapPortableStudioServersBlockingPorts(preferred, count) {
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
const start = Math.max(1, Math.min(65535, Math.trunc(preferred)));
|
|
2443
|
-
const end = Math.max(start, Math.min(65535, start + Math.max(1, Math.trunc(count)) - 1));
|
|
2444
|
-
const script = `
|
|
2445
|
-
$ErrorActionPreference = 'SilentlyContinue'
|
|
2446
|
-
$ports = ${start}..${end}
|
|
2447
|
-
$connections = @(Get-NetTCPConnection -State Listen | Where-Object { $ports -contains $_.LocalPort })
|
|
2448
|
-
$owners = @{}
|
|
2449
|
-
foreach ($conn in $connections) {
|
|
2450
|
-
$pidValue = [int]$conn.OwningProcess
|
|
2451
|
-
if ($pidValue -le 0 -or $owners.ContainsKey($pidValue)) { continue }
|
|
2452
|
-
$proc = Get-CimInstance Win32_Process -Filter "ProcessId=$pidValue"
|
|
2453
|
-
if ($null -eq $proc) { continue }
|
|
2454
|
-
$path = [string]$proc.ExecutablePath
|
|
2455
|
-
$cmd = [string]$proc.CommandLine
|
|
2456
|
-
$isPortableStudio = (
|
|
2457
|
-
$path -match '\\\\Tapi\\\\Studio\\\\server\\\\releases\\\\' -or
|
|
2458
|
-
$cmd -match 'tapi-studio-server'
|
|
2459
|
-
)
|
|
2460
|
-
if ($isPortableStudio) {
|
|
2461
|
-
$owners[$pidValue] = $true
|
|
2462
|
-
}
|
|
2463
|
-
}
|
|
2464
|
-
$stopped = 0
|
|
2465
|
-
foreach ($pidValue in $owners.Keys) {
|
|
2466
|
-
try {
|
|
2467
|
-
Stop-Process -Id $pidValue -Force -ErrorAction Stop
|
|
2468
|
-
$stopped += 1
|
|
2469
|
-
} catch {}
|
|
2470
|
-
}
|
|
2471
|
-
[pscustomobject]@{ stopped = $stopped } | ConvertTo-Json -Compress
|
|
2472
|
-
`;
|
|
2473
|
-
try {
|
|
2474
|
-
const output = await runProcessCapture("powershell.exe", [
|
|
2475
|
-
"-NoProfile",
|
|
2476
|
-
"-ExecutionPolicy",
|
|
2477
|
-
"Bypass",
|
|
2478
|
-
"-Command",
|
|
2479
|
-
script,
|
|
2480
|
-
]);
|
|
2481
|
-
const payload = JSON.parse(output.trim() || "{}");
|
|
2482
|
-
return typeof payload.stopped === "number" ? payload.stopped : 0;
|
|
2483
|
-
}
|
|
2484
|
-
catch {
|
|
2485
|
-
return 0;
|
|
2486
|
-
}
|
|
2439
|
+
void preferred;
|
|
2440
|
+
void count;
|
|
2441
|
+
return 0;
|
|
2487
2442
|
}
|
|
2488
2443
|
async function stopPortableStudioServerProcesses() {
|
|
2489
2444
|
if (process.platform !== "win32") {
|
|
@@ -2492,26 +2447,24 @@ async function stopPortableStudioServerProcesses() {
|
|
|
2492
2447
|
const script = `
|
|
2493
2448
|
$ErrorActionPreference = 'SilentlyContinue'
|
|
2494
2449
|
$currentPid = $PID
|
|
2495
|
-
$processes = @(Get-
|
|
2496
|
-
$pidValue = [int]$_.
|
|
2450
|
+
$processes = @(Get-Process -ErrorAction SilentlyContinue | Where-Object {
|
|
2451
|
+
$pidValue = [int]$_.Id
|
|
2497
2452
|
if ($pidValue -le 0 -or $pidValue -eq $currentPid) {
|
|
2498
2453
|
$false
|
|
2499
2454
|
} else {
|
|
2500
|
-
$path =
|
|
2501
|
-
$
|
|
2502
|
-
$name = [string]$_.
|
|
2455
|
+
$path = ''
|
|
2456
|
+
try { $path = [string]$_.Path } catch {}
|
|
2457
|
+
$name = [string]$_.ProcessName
|
|
2503
2458
|
(
|
|
2504
|
-
$name -ieq 'tapi-studio-server
|
|
2505
|
-
$path -match '\\\\Tapi\\\\Studio\\\\server\\\\releases\\\\'
|
|
2506
|
-
$cmd -match 'tapi-studio-server' -or
|
|
2507
|
-
$cmd -match 'scripts[\\\\/]studio\\.py'
|
|
2459
|
+
$name -ieq 'tapi-studio-server' -or
|
|
2460
|
+
$path -match '\\\\Tapi\\\\Studio\\\\server\\\\releases\\\\'
|
|
2508
2461
|
)
|
|
2509
2462
|
}
|
|
2510
2463
|
})
|
|
2511
2464
|
$stopped = 0
|
|
2512
2465
|
foreach ($process in $processes) {
|
|
2513
2466
|
try {
|
|
2514
|
-
Stop-Process -Id ([int]$process.
|
|
2467
|
+
Stop-Process -Id ([int]$process.Id) -Force -ErrorAction Stop
|
|
2515
2468
|
$stopped += 1
|
|
2516
2469
|
} catch {}
|
|
2517
2470
|
}
|
|
@@ -2524,7 +2477,7 @@ foreach ($process in $processes) {
|
|
|
2524
2477
|
"Bypass",
|
|
2525
2478
|
"-Command",
|
|
2526
2479
|
script,
|
|
2527
|
-
]);
|
|
2480
|
+
], { timeoutMs: WINDOWS_SERVICE_STATUS_TIMEOUT_MS });
|
|
2528
2481
|
const payload = JSON.parse(output.trim() || "{}");
|
|
2529
2482
|
return typeof payload.stopped === "number" ? payload.stopped : 0;
|
|
2530
2483
|
}
|