Skip to content

Commit 47cd20f

Browse files
authored
Check for cli version updates (#160)
1 parent ad8c29c commit 47cd20f

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

.github/workflows/ci_packages_cli.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: apps/cli
1+
name: packages/cli
22
on:
33
push:
44
branches: ["master"]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"overrides": {
1616
"highlight.js": "11.11.1",
1717
"hightable": "0.10.0",
18-
"hyparquet": "1.8.2",
18+
"hyparquet": "1.8.4",
1919
"hyparquet-compressors": "1.0.0",
2020
"react": "18.3.1",
2121
"react-dom": "18.3.1"

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
"typecheck": "tsc"
2929
},
3030
"dependencies": {
31+
"@hyparam/components": "0.1.17",
3132
"highlight.js": "11.11.1",
3233
"hightable": "0.10.0",
33-
"@hyparam/components": "0.1.17",
3434
"react": "18.3.1",
3535
"react-dom": "18.3.1"
3636
},

packages/cli/src/cli.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#!/usr/bin/env node
22

33
import fs from 'fs/promises'
4-
import hyperparamPackage from '../package.json' with { type: 'json' }
4+
import packageJson from '../package.json' with { type: 'json' }
55
import { chat } from './chat.js'
66
import { serve } from './serve.js'
77

8+
const updateCheck = checkForUpdates()
9+
810
const arg = process.argv[2]
911
if (arg === 'chat') {
12+
await updateCheck // wait for update check to finish before chat
1013
chat()
1114
} else if (arg === '--help' || arg === '-H' || arg === '-h') {
1215
console.log('Usage:')
@@ -17,7 +20,7 @@ if (arg === 'chat') {
1720
console.log(' hyperparam -h, --help, give this help list')
1821
console.log(' hyperparam -v, --version print program version')
1922
} else if (arg === '--version' || arg === '-V' || arg === '-v') {
20-
console.log(hyperparamPackage.version)
23+
console.log(packageJson.version)
2124
} else if (!arg) {
2225
serve(process.cwd(), undefined) // current directory
2326
} else if (arg.match(/^https?:\/\//)) {
@@ -38,3 +41,22 @@ if (arg === 'chat') {
3841
process.exit(1)
3942
})
4043
}
44+
45+
/**
46+
* Check for updates and notify user if a newer version is available.
47+
* Runs in the background.
48+
* @returns {Promise<void>}
49+
*/
50+
function checkForUpdates() {
51+
const currentVersion = packageJson.version
52+
return fetch('https://registry.npmjs.org/hyperparam/latest')
53+
.then(response => response.json())
54+
.then(data => {
55+
const latestVersion = data.version
56+
if (latestVersion && latestVersion !== currentVersion) {
57+
console.log(`\x1b[33mA newer version of hyperparam is available: ${latestVersion} (current: ${currentVersion})\x1b[0m`)
58+
console.log('\x1b[33mRun \'npm install -g hyperparam\' to update\x1b[0m')
59+
}
60+
})
61+
.catch(() => {}) // ignore errors
62+
}

packages/components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
},
4242
"dependencies": {
4343
"hightable": "0.10.0",
44-
"hyparquet": "1.8.2",
44+
"hyparquet": "1.8.4",
4545
"hyparquet-compressors": "1.0.0"
4646
},
4747
"peerDependencies": {

0 commit comments

Comments
 (0)