@antigenic-oss/paint 0.3.2 → 0.3.4

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.
Files changed (2) hide show
  1. package/bin/paint.js +58 -9
  2. package/package.json +1 -1
package/bin/paint.js CHANGED
@@ -338,6 +338,55 @@ function stopProcess(pid) {
338
338
  }
339
339
  }
340
340
 
341
+ function killAndWait(pid, timeoutMs = 5000) {
342
+ if (!Number.isInteger(pid) || pid <= 0) return true
343
+
344
+ if (process.platform === 'win32') {
345
+ const result = spawnSync('taskkill', ['/PID', String(pid), '/T', '/F'], {
346
+ stdio: 'ignore',
347
+ })
348
+ return result.status === 0
349
+ }
350
+
351
+ // Send SIGTERM first
352
+ try {
353
+ process.kill(-pid, 'SIGTERM')
354
+ } catch {
355
+ try {
356
+ process.kill(pid, 'SIGTERM')
357
+ } catch {
358
+ return true // already dead
359
+ }
360
+ }
361
+
362
+ // Wait for the process to die
363
+ const start = Date.now()
364
+ while (Date.now() - start < timeoutMs) {
365
+ if (!isProcessAlive(pid)) return true
366
+ spawnSync('sleep', ['0.1'])
367
+ }
368
+
369
+ // Still alive — escalate to SIGKILL
370
+ try {
371
+ process.kill(-pid, 'SIGKILL')
372
+ } catch {
373
+ try {
374
+ process.kill(pid, 'SIGKILL')
375
+ } catch {
376
+ return !isProcessAlive(pid)
377
+ }
378
+ }
379
+
380
+ // Brief wait after SIGKILL
381
+ const killStart = Date.now()
382
+ while (Date.now() - killStart < 2000) {
383
+ if (!isProcessAlive(pid)) return true
384
+ spawnSync('sleep', ['0.1'])
385
+ }
386
+
387
+ return !isProcessAlive(pid)
388
+ }
389
+
341
390
  function validatePort(port, flagName) {
342
391
  if (!Number.isInteger(port) || port <= 0 || port > 65535) {
343
392
  console.error(`Invalid ${flagName} value: ${port}`)
@@ -527,7 +576,7 @@ async function startApp(options) {
527
576
  checkForUpdate()
528
577
  }
529
578
 
530
- function stopApp() {
579
+ function stopApp({ force = false } = {}) {
531
580
  const existing = readState(APP_STATE_FILE)
532
581
  if (!existing) {
533
582
  console.log('pAInt is not running.')
@@ -535,7 +584,7 @@ function stopApp() {
535
584
  }
536
585
 
537
586
  const alive = isProcessAlive(existing.webPid)
538
- const ok = alive ? stopProcess(existing.webPid) : true
587
+ const ok = alive ? (force ? killAndWait(existing.webPid) : stopProcess(existing.webPid)) : true
539
588
  removeState(APP_STATE_FILE)
540
589
 
541
590
  if (!alive) {
@@ -633,7 +682,7 @@ async function startTerminal(options) {
633
682
  console.log(`Terminal logs: ${TERMINAL_LOG_FILE}`)
634
683
  }
635
684
 
636
- function stopTerminal() {
685
+ function stopTerminal({ force = false } = {}) {
637
686
  const existing = readState(TERMINAL_STATE_FILE)
638
687
  if (!existing) {
639
688
  console.log('Terminal is not running.')
@@ -641,7 +690,7 @@ function stopTerminal() {
641
690
  }
642
691
 
643
692
  const alive = isProcessAlive(existing.terminalPid)
644
- const ok = alive ? stopProcess(existing.terminalPid) : true
693
+ const ok = alive ? (force ? killAndWait(existing.terminalPid) : stopProcess(existing.terminalPid)) : true
645
694
  removeState(TERMINAL_STATE_FILE)
646
695
 
647
696
  if (!alive) {
@@ -736,7 +785,7 @@ async function startBridge(options) {
736
785
  console.log(`Bridge logs: ${BRIDGE_LOG_FILE}`)
737
786
  }
738
787
 
739
- function stopBridge() {
788
+ function stopBridge({ force = false } = {}) {
740
789
  const existing = readState(BRIDGE_STATE_FILE)
741
790
  if (!existing) {
742
791
  console.log('Bridge is not running.')
@@ -744,7 +793,7 @@ function stopBridge() {
744
793
  }
745
794
 
746
795
  const alive = isProcessAlive(existing.bridgePid)
747
- const ok = alive ? stopProcess(existing.bridgePid) : true
796
+ const ok = alive ? (force ? killAndWait(existing.bridgePid) : stopProcess(existing.bridgePid)) : true
748
797
  removeState(BRIDGE_STATE_FILE)
749
798
 
750
799
  if (!alive) {
@@ -852,7 +901,7 @@ async function main() {
852
901
  stopBridge()
853
902
  return
854
903
  case 'restart':
855
- stopBridge()
904
+ stopBridge({ force: true })
856
905
  await startBridge(options)
857
906
  return
858
907
  case 'status':
@@ -876,7 +925,7 @@ async function main() {
876
925
  stopTerminal()
877
926
  return
878
927
  case 'restart':
879
- stopTerminal()
928
+ stopTerminal({ force: true })
880
929
  await startTerminal(options)
881
930
  return
882
931
  case 'status':
@@ -899,7 +948,7 @@ async function main() {
899
948
  stopApp()
900
949
  break
901
950
  case 'restart':
902
- stopApp()
951
+ stopApp({ force: true })
903
952
  await startApp(options)
904
953
  break
905
954
  case 'status':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antigenic-oss/paint",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "Visual editor for localhost web projects with a global paint CLI",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/Antigenic-OSS/pAInt",