@supalytics/cli 0.3.4 → 0.3.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supalytics/cli",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "CLI for Supalytics web analytics",
5
5
  "type": "module",
6
6
  "bin": {
@@ -12,7 +12,10 @@
12
12
  "README.md"
13
13
  ],
14
14
  "scripts": {
15
- "dev": "bun run src/index.ts"
15
+ "dev": "bun run src/index.ts",
16
+ "release:patch": "npm version patch --no-git-tag-version && npm publish",
17
+ "release:minor": "npm version minor --no-git-tag-version && npm publish",
18
+ "release:major": "npm version major --no-git-tag-version && npm publish"
16
19
  },
17
20
  "keywords": [
18
21
  "analytics",
@@ -34,6 +37,7 @@
34
37
  "dependencies": {
35
38
  "chalk": "^5.6.2",
36
39
  "commander": "^14.0.2",
37
- "open": "^10.1.0"
40
+ "open": "^10.1.0",
41
+ "update-notifier": "^7.3.1"
38
42
  }
39
43
  }
@@ -0,0 +1,54 @@
1
+ import { Command } from "commander";
2
+ import chalk from "chalk";
3
+ import { $ } from "bun";
4
+
5
+ export const updateCommand = new Command("update")
6
+ .description("Update Supalytics CLI to the latest version")
7
+ .action(async () => {
8
+ // Read current version
9
+ const pkg = await Bun.file(new URL("../../package.json", import.meta.url)).json();
10
+ console.log(chalk.dim(`Current version: ${pkg.version}`));
11
+ console.log(chalk.dim("Checking for updates..."));
12
+ console.log();
13
+
14
+ try {
15
+ // Check latest version from npm
16
+ const response = await fetch("https://registry.npmjs.org/@supalytics/cli/latest");
17
+ if (!response.ok) {
18
+ throw new Error("Failed to check npm registry");
19
+ }
20
+ const data = await response.json();
21
+ const latestVersion = data.version;
22
+
23
+ if (latestVersion === pkg.version) {
24
+ console.log(chalk.green("✓ Already on the latest version"));
25
+ return;
26
+ }
27
+
28
+ console.log(chalk.cyan(`New version available: ${latestVersion}`));
29
+ console.log();
30
+ console.log(chalk.dim("Updating..."));
31
+
32
+ // Try bun first, fall back to npm
33
+ try {
34
+ await $`bun upgrade @supalytics/cli`.quiet();
35
+ console.log(chalk.green(`✓ Updated to ${latestVersion}`));
36
+ } catch {
37
+ // bun upgrade might not work for global packages, try npm
38
+ try {
39
+ await $`npm update -g @supalytics/cli`.quiet();
40
+ console.log(chalk.green(`✓ Updated to ${latestVersion}`));
41
+ } catch {
42
+ console.log(chalk.yellow("Automatic update failed."));
43
+ console.log();
44
+ console.log("Please update manually:");
45
+ console.log(chalk.cyan(" bun install -g @supalytics/cli@latest"));
46
+ console.log(" or");
47
+ console.log(chalk.cyan(" npm install -g @supalytics/cli@latest"));
48
+ }
49
+ }
50
+ } catch (error) {
51
+ console.error(chalk.red(`Error: ${(error as Error).message}`));
52
+ process.exit(1);
53
+ }
54
+ });
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env bun
2
2
  import { program } from "commander";
3
+ import updateNotifier from "update-notifier";
3
4
  import { loginCommand } from "./commands/login";
4
5
  import { logoutCommand } from "./commands/logout";
5
6
  import { sitesCommand, defaultCommand, removeCommand } from "./commands/sites";
@@ -13,6 +14,7 @@ import { eventsCommand } from "./commands/events";
13
14
  import { realtimeCommand } from "./commands/realtime";
14
15
  import { completionsCommand } from "./commands/completions";
15
16
  import { initCommand } from "./commands/init";
17
+ import { updateCommand } from "./commands/update";
16
18
 
17
19
  const description = `CLI for Supalytics web analytics.
18
20
 
@@ -64,6 +66,9 @@ Output:
64
66
  // Read version from package.json
65
67
  const pkg = await Bun.file(new URL("../package.json", import.meta.url)).json();
66
68
 
69
+ // Check for updates (runs in background, non-blocking)
70
+ updateNotifier({ pkg }).notify();
71
+
67
72
  program
68
73
  .name("supalytics")
69
74
  .description(description)
@@ -90,4 +95,7 @@ program.addCommand(eventsCommand);
90
95
  program.addCommand(realtimeCommand);
91
96
  program.addCommand(completionsCommand);
92
97
 
98
+ // Utility commands
99
+ program.addCommand(updateCommand);
100
+
93
101
  program.parse();