@jxtools/visualgit 1.4.0 → 1.5.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.
- package/README.md +1 -1
- package/bin/cli.js +28 -2
- package/package.json +1 -1
package/README.md
CHANGED
package/bin/cli.js
CHANGED
|
@@ -3,16 +3,42 @@
|
|
|
3
3
|
import { existsSync, readFileSync } from 'fs'
|
|
4
4
|
import { resolve, dirname } from 'path'
|
|
5
5
|
import { fileURLToPath } from 'url'
|
|
6
|
-
import { spawn } from 'child_process'
|
|
6
|
+
import { spawn, execSync } from 'child_process'
|
|
7
7
|
|
|
8
8
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
9
|
+
const pkg = JSON.parse(readFileSync(resolve(__dirname, '..', 'package.json'), 'utf-8'))
|
|
9
10
|
|
|
10
11
|
if (process.argv.includes('--version') || process.argv.includes('-v')) {
|
|
11
|
-
const pkg = JSON.parse(readFileSync(resolve(__dirname, '..', 'package.json'), 'utf-8'))
|
|
12
12
|
console.log(`visualgit v${pkg.version}`)
|
|
13
13
|
process.exit(0)
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
if (process.argv[2] === 'update') {
|
|
17
|
+
const current = pkg.version
|
|
18
|
+
console.log(`\x1b[36m⟳\x1b[0m Current version: v${current}`)
|
|
19
|
+
console.log(` Checking for updates...`)
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const latest = execSync('npm view @jxtools/visualgit version', { encoding: 'utf-8' }).trim()
|
|
23
|
+
|
|
24
|
+
if (latest === current) {
|
|
25
|
+
console.log(`\x1b[32m✓\x1b[0m Already on the latest version (v${current})`)
|
|
26
|
+
process.exit(0)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
console.log(`\x1b[33m↑\x1b[0m New version available: v${latest}`)
|
|
30
|
+
console.log(` Updating...`)
|
|
31
|
+
|
|
32
|
+
execSync('npm install -g @jxtools/visualgit@latest', { stdio: 'inherit' })
|
|
33
|
+
console.log(`\n\x1b[32m✓\x1b[0m Updated to v${latest}`)
|
|
34
|
+
} catch (err) {
|
|
35
|
+
console.error(`\x1b[31m✗\x1b[0m Update failed: ${err.message}`)
|
|
36
|
+
process.exit(1)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
process.exit(0)
|
|
40
|
+
}
|
|
41
|
+
|
|
16
42
|
const repoPath = process.cwd()
|
|
17
43
|
const isGitRepo = existsSync(resolve(repoPath, '.git'))
|
|
18
44
|
|