vibex-sh 0.1.1 → 0.2.0

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/index.js +36 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -3,17 +3,38 @@ import { io } from 'socket.io-client';
3
3
  import { program, Command } from 'commander';
4
4
  import { readFile, writeFile, mkdir } from 'fs/promises';
5
5
  import { existsSync, readFileSync } from 'fs';
6
- import { join } from 'path';
6
+ import { join, dirname } from 'path';
7
7
  import { homedir } from 'os';
8
8
  import { spawn } from 'child_process';
9
9
  import http from 'http';
10
10
  import https from 'https';
11
+ import { fileURLToPath } from 'url';
12
+
13
+ // Get version from package.json
14
+ const __filename = fileURLToPath(import.meta.url);
15
+ const __dirname = dirname(__filename);
16
+ const packageJsonPath = join(__dirname, 'package.json');
17
+ let cliVersion = '0.0.0';
18
+ try {
19
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
20
+ cliVersion = packageJson.version || '0.0.0';
21
+ } catch (error) {
22
+ // Fallback if package.json can't be read - try to read from parent directory
23
+ try {
24
+ const parentPackageJsonPath = join(__dirname, '..', 'package.json');
25
+ const packageJson = JSON.parse(readFileSync(parentPackageJsonPath, 'utf8'));
26
+ cliVersion = packageJson.version || '0.0.0';
27
+ } catch (e) {
28
+ // If both fail, use default
29
+ }
30
+ }
31
+
32
+ import crypto from 'crypto';
11
33
 
12
34
  function generateSessionId() {
13
35
  // Generate secure random session ID with 12 characters (as per security plan)
14
36
  // Format: vibex-{12 random alphanumeric chars}
15
37
  // Using crypto for better randomness
16
- const crypto = require('crypto');
17
38
  const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
18
39
  let result = 'vibex-';
19
40
 
@@ -281,7 +302,7 @@ function printBanner(sessionId, webUrl, authCode = null) {
281
302
 
282
303
  console.log('\n');
283
304
  console.log(' ╔═══════════════════════════════════════╗');
284
- console.log(' ║ 🔍 vibex.sh is watching... ║');
305
+ console.log(' ║ 🔍 vibex.sh is watching... ║');
285
306
  console.log(' ╚═══════════════════════════════════════╝');
286
307
  console.log('\n');
287
308
  console.log(` Session ID: ${sessionId}`);
@@ -293,12 +314,19 @@ function printBanner(sessionId, webUrl, authCode = null) {
293
314
  }
294
315
 
295
316
  async function main() {
296
- // Handle login command separately - check BEFORE commander parses
297
- // Check process.argv directly - look for 'login' as a standalone argument
298
- // This must happen FIRST, before any commander parsing
317
+ // Handle --version flag early (before commander parses)
299
318
  const allArgs = process.argv;
300
319
  const args = process.argv.slice(2);
301
320
 
321
+ // Check for --version or -V flag
322
+ if (allArgs.includes('--version') || allArgs.includes('-V') || args.includes('--version') || args.includes('-V')) {
323
+ console.log(cliVersion);
324
+ process.exit(0);
325
+ }
326
+
327
+ // Handle login command separately - check BEFORE commander parses
328
+ // Check process.argv directly - look for 'login' as a standalone argument
329
+ // This must happen FIRST, before any commander parsing
302
330
  // Check if 'login' appears anywhere in process.argv (works with npx too)
303
331
  const hasLogin = allArgs.includes('login') || args.includes('login');
304
332
 
@@ -328,6 +356,7 @@ async function main() {
328
356
  }
329
357
 
330
358
  program
359
+ .version(cliVersion, '-v, --version', 'Display version number')
331
360
  .option('-s, --session-id <id>', 'Reuse existing session ID')
332
361
  .option('-l, --local', 'Use localhost (web: 3000, socket: 3001)')
333
362
  .option('--web <url>', 'Web server URL (e.g., http://localhost:3000)')
@@ -365,7 +394,7 @@ async function main() {
365
394
  const localFlag = webUrl.includes('localhost') ? ' --local' : '';
366
395
  const sessionSlug = sessionId.replace(/^vibex-/, ''); // Remove prefix for example
367
396
  console.log(' 💡 Tip: Use -s to send more logs to this session');
368
- console.log(` Example: echo '{"cpu": 45, "memory": 78, "timestamp": "${new Date().toISOString()}"}' | npx vibex-sh -s ${sessionSlug}${localFlag}\n`);
397
+ console.log(` Example: echo '{"cpu": 45, "memory": 78}' | npx vibex-sh -s ${sessionSlug}${localFlag}\n`);
369
398
  } else {
370
399
  // When reusing a session, show minimal info
371
400
  const dashboardUrl = authCode
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vibex-sh",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Zero-config observability CLI - pipe logs and visualize instantly",
5
5
  "type": "module",
6
6
  "bin": {