@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 +1 -1
- package/src/commands/update.ts +68 -52
package/package.json
CHANGED
package/src/commands/update.ts
CHANGED
|
@@ -1,54 +1,70 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import chalk from "chalk"
|
|
3
|
-
import {
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
+
})
|