@seflless/ghosttown 1.4.0 → 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.
- package/package.json +1 -1
- package/src/cli.js +50 -7
package/package.json
CHANGED
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,29 +412,58 @@ 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
|
+
|
|
409
431
|
/**
|
|
410
432
|
* Update ghosttown to the latest version
|
|
411
433
|
*/
|
|
412
434
|
function updateGhosttown() {
|
|
413
435
|
const RESET = '\x1b[0m';
|
|
414
|
-
const CYAN = '\x1b[36m';
|
|
415
436
|
const BEIGE = '\x1b[38;2;255;220;150m';
|
|
416
437
|
const BOLD_YELLOW = '\x1b[1;93m';
|
|
417
438
|
const DIM = '\x1b[2m';
|
|
418
439
|
|
|
440
|
+
// Get current version before updating
|
|
441
|
+
const oldVersion = getInstalledVersion();
|
|
442
|
+
|
|
419
443
|
console.log('');
|
|
420
|
-
console.log(` ${BOLD_YELLOW}
|
|
444
|
+
console.log(` ${BOLD_YELLOW}Checking for ghosttown updates...${RESET}`);
|
|
421
445
|
console.log('');
|
|
422
446
|
|
|
423
447
|
try {
|
|
448
|
+
// Run npm install silently (suppress output)
|
|
424
449
|
execSync('npm install -g @seflless/ghosttown', {
|
|
425
|
-
stdio: '
|
|
450
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
426
451
|
});
|
|
427
452
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
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
|
+
}
|
|
432
467
|
console.log('');
|
|
433
468
|
} catch (err) {
|
|
434
469
|
console.log('');
|
|
@@ -556,6 +591,7 @@ Usage: ghosttown [options] [command]
|
|
|
556
591
|
Options:
|
|
557
592
|
-p, --port <port> Port to listen on (default: 8080, or PORT env var)
|
|
558
593
|
-k, --kill [session] Kill a session (current if inside one, or specify)
|
|
594
|
+
-v, --version Show version number
|
|
559
595
|
-h, --help Show this help message
|
|
560
596
|
|
|
561
597
|
Commands:
|
|
@@ -584,6 +620,13 @@ Aliases:
|
|
|
584
620
|
break;
|
|
585
621
|
}
|
|
586
622
|
|
|
623
|
+
// Handle version flag
|
|
624
|
+
if (arg === '-v' || arg === '--version') {
|
|
625
|
+
console.log(VERSION);
|
|
626
|
+
handled = true;
|
|
627
|
+
break;
|
|
628
|
+
}
|
|
629
|
+
|
|
587
630
|
// Handle list command
|
|
588
631
|
if (arg === 'list') {
|
|
589
632
|
handled = true;
|