Skip to content
This repository was archived by the owner on Sep 12, 2019. It is now read-only.

Commit 2d69d23

Browse files
committed
Check for tunnel client updates.
Signed-off-by: David Calavera <[email protected]>
1 parent 472fcb2 commit 2d69d23

File tree

3 files changed

+62
-38
lines changed

3 files changed

+62
-38
lines changed

package-lock.json

Lines changed: 39 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
"@oclif/config": "^1",
1212
"ascii-table": "0.0.9",
1313
"copy-template-dir": "^1.4.0",
14+
"execa": "^1.0.0",
1415
"fs-extra": "^7.0.1",
1516
"fuzzy": "^0.1.3",
1617
"get-port": "^4.1.0",
17-
"gh-release-fetch": "^1.0.1",
18+
"gh-release-fetch": "^1.0.3",
1819
"http-proxy": "^1.17.0",
1920
"inquirer": "^6.2.2",
2021
"inquirer-autocomplete-prompt": "^1.0.1",

src/live-tunnel.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const fetch = require('node-fetch')
22
const fs = require('fs')
33
const os = require('os')
44
const path = require('path')
5-
const { fetchLatest } = require('gh-release-fetch')
5+
const { fetchLatest, updateAvailable } = require('gh-release-fetch')
66
const { runProcess } = require('./run-process')
77

88
async function createTunnel(siteId, netlifyApiToken, log) {
@@ -43,7 +43,8 @@ async function connectTunnel(session, netlifyApiToken, localPort, log, error) {
4343
async function installTunnelClient(log) {
4444
const binPath = path.join(os.homedir(), '.netlify', 'tunnel', 'bin')
4545
const execPath = path.join(binPath, 'live-tunnel-client')
46-
if (execExist(execPath)) {
46+
const newVersion = fetchTunnelClient(execPath)
47+
if (!newVersion) {
4748
return
4849
}
4950

@@ -61,6 +62,24 @@ async function installTunnelClient(log) {
6162
await fetchLatest(release)
6263
}
6364

65+
async function fetchTunnelClient(execPath) {
66+
if (!execExist(execPath)) {
67+
return true
68+
}
69+
70+
const { stdout } = await execa(execPath, ['version'])
71+
if (!stdout) {
72+
return false
73+
}
74+
75+
const match = stdout.match(/^live-tunnel-client\/v([^\s]+)/)
76+
if (!match) {
77+
return false
78+
}
79+
80+
return updateAvailable(match[1])
81+
}
82+
6483
function execExist(binPath) {
6584
if (!fs.existsSync(binPath)) {
6685
return false

0 commit comments

Comments
 (0)