Skip to content

Commit 006f46c

Browse files
committed
Support for Vercel and GitHub Private Repo (#62 #39)
1 parent e5cf41e commit 006f46c

File tree

9 files changed

+52
-23
lines changed

9 files changed

+52
-23
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ coverage
33

44
# dependencies
55
node_modules
6+
7+
# vercel
8+
.vercel
File renamed without changes.

lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module.exports = config => {
3535
router.get('/download', routes.download)
3636
router.get('/download/:platform', routes.downloadPlatform)
3737
router.get('/update/:platform/:version', routes.update)
38+
router.get('/update/:platform/:version/:targetFile', routes.update)
3839
router.get('/update/win32/:version/RELEASES', routes.releases)
3940

4041
return (req, res) => {

lib/platform.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ module.exports = fileName => {
66

77
if (
88
(fileName.includes('mac') || fileName.includes('darwin')) &&
9-
extension === 'zip'
9+
(extension === 'yml')
1010
) {
1111
return 'darwin'
1212
}
1313

14-
const directCache = ['exe', 'dmg', 'rpm', 'deb', 'AppImage']
14+
const directCache = ['exe', 'dmg', 'rpm', 'deb', 'AppImage', 'zip']
1515
return directCache.find(ext => ext === extension) || false
1616
}

lib/routes.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Native
2-
const urlHelpers = require('url');
2+
const urlHelpers = require('url')
33

44
// Packages
55
const { send } = require('micro')
@@ -81,6 +81,10 @@ module.exports = ({ cache, config }) => {
8181
platform = 'dmg'
8282
}
8383

84+
if (platform === 'darwin') {
85+
platform = 'dmg'
86+
}
87+
8488
// Get the latest version from the cache
8589
const latest = await loadCache()
8690

@@ -110,7 +114,7 @@ module.exports = ({ cache, config }) => {
110114
}
111115

112116
exports.update = async (req, res) => {
113-
const { platform: platformName, version } = req.params
117+
const { platform: platformName, version, targetFile } = req.params
114118

115119
if (!valid(version)) {
116120
send(res, 500, {
@@ -142,6 +146,18 @@ module.exports = ({ cache, config }) => {
142146
return
143147
}
144148

149+
if (targetFile) {
150+
if (shouldProxyPrivateDownload) {
151+
for (const platform in latest.platforms) {
152+
if (latest.platforms[platform].name === targetFile) {
153+
proxyPrivateDownload(latest.platforms[platform], req, res)
154+
break
155+
}
156+
}
157+
return
158+
}
159+
}
160+
145161
// Previously, we were checking if the latest version is
146162
// greater than the one on the client. However, we
147163
// only need to compare if they're different (even if

lib/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const hazel = require('./index')
1+
const hazel = require('.')
22

33
const {
44
INTERVAL: interval,

now.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,30 @@
2323
},
2424
"lint-staged": {
2525
"*.js": [
26-
"yarn test && :",
26+
"yarn test --passWithNoTests && :",
2727
"prettier --single-quote --no-semi --write --no-editorconfig",
2828
"git add"
2929
]
3030
},
3131
"dependencies": {
32+
"@vercel/node": "^1.8.2",
3233
"async-retry": "1.2.3",
3334
"date-fns": "1.29.0",
3435
"express-useragent": "1.0.12",
3536
"fetch": "1.1.0",
3637
"finalhandler": "1.1.0",
3738
"handlebars": "4.0.11",
39+
"install": "^0.13.0",
3840
"jest": "24.0.0",
3941
"micro": "9.3.3",
4042
"ms": "2.1.1",
4143
"node-fetch": "2.0.0",
4244
"router": "1.3.2",
4345
"semver": "5.5.0",
4446
"stream-to-string": "1.1.0",
45-
"test-listen": "1.1.0"
47+
"test-listen": "1.1.0",
48+
"vercel": "^20.1.0",
49+
"yarn": "^1.22.10"
4650
},
4751
"devDependencies": {
4852
"eslint-config-prettier": "2.9.0",

vercel.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"version": 2,
3+
"env": {
4+
"ACCOUNT": "Your GitHub Account",
5+
"REPOSITORY": "Yout GitHub Repository",
6+
"TOKEN": "Your GitHub Token",
7+
"URL": "http://localhost:3000"
8+
},
9+
"builds": [
10+
{
11+
"src": "lib/*.js",
12+
"use": "@vercel/node"
13+
}
14+
],
15+
"routes": [
16+
{
17+
"src": ".*",
18+
"dest": "lib/server.js"
19+
}
20+
]
21+
}

0 commit comments

Comments
 (0)