@supalytics/cli 0.4.0 → 0.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supalytics/cli",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "CLI for Supalytics web analytics",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,54 +1,70 @@
1
- import { Command } from "commander";
2
- import chalk from "chalk";
3
- import { $ } from "bun";
1
+ import { $ } from "bun"
2
+ import chalk from "chalk"
3
+ import { Command } from "commander"
4
4
 
5
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
- });
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 to update using the appropriate package manager
33
+ let updated = false
34
+
35
+ // Try bun first (bun add -g for global packages)
36
+ try {
37
+ await $`bun add -g @supalytics/cli@latest`.quiet()
38
+ updated = true
39
+ } catch {
40
+ // bun not available or failed, try npm
41
+ }
42
+
43
+ // Fall back to npm if bun didn't work
44
+ if (!updated) {
45
+ try {
46
+ await $`npm install -g @supalytics/cli@latest`.quiet()
47
+ updated = true
48
+ } catch {
49
+ // npm also failed
50
+ }
51
+ }
52
+
53
+ if (!updated) {
54
+ console.log(chalk.yellow("Automatic update failed."))
55
+ console.log()
56
+ console.log("Please update manually:")
57
+ console.log(chalk.cyan(" bun add -g @supalytics/cli@latest"))
58
+ console.log(" or")
59
+ console.log(chalk.cyan(" npm install -g @supalytics/cli@latest"))
60
+ return
61
+ }
62
+
63
+ console.log(chalk.green(`✓ Updated to ${latestVersion}`))
64
+ console.log()
65
+ console.log(chalk.dim("Run `supalytics --version` to verify"))
66
+ } catch (error) {
67
+ console.error(chalk.red(`Error: ${(error as Error).message}`))
68
+ process.exit(1)
69
+ }
70
+ })