@seflless/ghosttown 1.3.3 → 1.4.1

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/package.json +1 -1
  2. package/src/cli.js +87 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seflless/ghosttown",
3
- "version": "1.3.3",
3
+ "version": "1.4.1",
4
4
  "description": "Web-based terminal emulator using Ghostty's VT100 parser via WebAssembly",
5
5
  "type": "module",
6
6
  "main": "./dist/ghostty-web.umd.cjs",
package/src/cli.js CHANGED
@@ -21,6 +21,7 @@
21
21
  import { execSync, spawn, spawnSync } from 'child_process';
22
22
  import fs from 'fs';
23
23
  import http from 'http';
24
+ import { createRequire } from 'module';
24
25
  import { homedir, networkInterfaces } from 'os';
25
26
  import path from 'path';
26
27
  import { fileURLToPath } from 'url';
@@ -35,6 +36,11 @@ import { asciiArt } from '../bin/ascii.js';
35
36
  const __filename = fileURLToPath(import.meta.url);
36
37
  const __dirname = path.dirname(__filename);
37
38
 
39
+ // Get version from package.json
40
+ const require = createRequire(import.meta.url);
41
+ const packageJson = require('../package.json');
42
+ const VERSION = packageJson.version;
43
+
38
44
  // ============================================================================
39
45
  // Tmux Session Management
40
46
  // ============================================================================
@@ -406,6 +412,70 @@ function attachToSession(sessionName) {
406
412
  process.exit(result.status || 0);
407
413
  }
408
414
 
415
+ /**
416
+ * Get the currently installed version of ghosttown
417
+ */
418
+ function getInstalledVersion() {
419
+ try {
420
+ const output = execSync('npm list -g @seflless/ghosttown --json 2>/dev/null', {
421
+ encoding: 'utf8',
422
+ stdio: ['pipe', 'pipe', 'pipe'],
423
+ });
424
+ const data = JSON.parse(output);
425
+ return data.dependencies?.['@seflless/ghosttown']?.version || null;
426
+ } catch (err) {
427
+ return null;
428
+ }
429
+ }
430
+
431
+ /**
432
+ * Update ghosttown to the latest version
433
+ */
434
+ function updateGhosttown() {
435
+ const RESET = '\x1b[0m';
436
+ const BEIGE = '\x1b[38;2;255;220;150m';
437
+ const BOLD_YELLOW = '\x1b[1;93m';
438
+ const DIM = '\x1b[2m';
439
+
440
+ // Get current version before updating
441
+ const oldVersion = getInstalledVersion();
442
+
443
+ console.log('');
444
+ console.log(` ${BOLD_YELLOW}Checking for ghosttown updates...${RESET}`);
445
+ console.log('');
446
+
447
+ try {
448
+ // Run npm install silently (suppress output)
449
+ execSync('npm install -g @seflless/ghosttown', {
450
+ stdio: ['pipe', 'pipe', 'pipe'],
451
+ });
452
+
453
+ // Get new version after updating
454
+ const newVersion = getInstalledVersion();
455
+
456
+ if (oldVersion && newVersion && oldVersion === newVersion) {
457
+ console.log(` ${DIM}Already on the latest version: ${BEIGE}${newVersion}${RESET}`);
458
+ } else {
459
+ console.log(` ${BOLD_YELLOW}ghosttown has been updated!${RESET}`);
460
+ console.log('');
461
+ if (oldVersion && newVersion) {
462
+ console.log(` ${DIM}${oldVersion}${RESET} -> ${BEIGE}${newVersion}${RESET}`);
463
+ } else if (newVersion) {
464
+ console.log(` ${DIM}Version: ${BEIGE}${newVersion}${RESET}`);
465
+ }
466
+ }
467
+ console.log('');
468
+ } catch (err) {
469
+ console.log('');
470
+ console.log(` ${RESET}Failed to update ghosttown.${RESET}`);
471
+ console.log(` ${DIM}Try running with sudo: sudo npm install -g @seflless/ghosttown${RESET}`);
472
+ console.log('');
473
+ process.exit(1);
474
+ }
475
+
476
+ process.exit(0);
477
+ }
478
+
409
479
  /**
410
480
  * Kill a ghosttown session
411
481
  * If sessionName is null, kills the current session (if inside one)
@@ -521,12 +591,14 @@ Usage: ghosttown [options] [command]
521
591
  Options:
522
592
  -p, --port <port> Port to listen on (default: 8080, or PORT env var)
523
593
  -k, --kill [session] Kill a session (current if inside one, or specify)
594
+ -v, --version Show version number
524
595
  -h, --help Show this help message
525
596
 
526
597
  Commands:
527
598
  list List all ghosttown tmux sessions
528
599
  attach <session> Attach to a ghosttown session
529
600
  detach Detach from current ghosttown session
601
+ update Update ghosttown to the latest version
530
602
  <command> Run command in a new tmux session (ghosttown-<id>)
531
603
 
532
604
  Examples:
@@ -535,6 +607,7 @@ Examples:
535
607
  ghosttown list List all ghosttown sessions
536
608
  ghosttown attach ghosttown-1 Attach to session ghosttown-1
537
609
  ghosttown detach Detach from current session
610
+ ghosttown update Update to the latest version
538
611
  ghosttown -k Kill current session (when inside one)
539
612
  ghosttown -k ghosttown-1 Kill a specific session
540
613
  ghosttown vim Run vim in a new tmux session
@@ -547,6 +620,13 @@ Aliases:
547
620
  break;
548
621
  }
549
622
 
623
+ // Handle version flag
624
+ if (arg === '-v' || arg === '--version') {
625
+ console.log(VERSION);
626
+ handled = true;
627
+ break;
628
+ }
629
+
550
630
  // Handle list command
551
631
  if (arg === 'list') {
552
632
  handled = true;
@@ -561,6 +641,13 @@ Aliases:
561
641
  // detachFromTmux exits, so this won't be reached
562
642
  }
563
643
 
644
+ // Handle update command
645
+ else if (arg === 'update') {
646
+ handled = true;
647
+ updateGhosttown();
648
+ // updateGhosttown exits, so this won't be reached
649
+ }
650
+
564
651
  // Handle attach command
565
652
  else if (arg === 'attach') {
566
653
  const sessionArg = args[i + 1];