Skip to content

Commit

Permalink
Support for Vercel and GitHub Private Repo (#62 #39)
Browse files Browse the repository at this point in the history
  • Loading branch information
backroot committed Oct 4, 2020
1 parent e5cf41e commit b232ee3
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ coverage

# dependencies
node_modules

# vercel
.vercel
File renamed without changes.
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = config => {
router.get('/download', routes.download)
router.get('/download/:platform', routes.downloadPlatform)
router.get('/update/:platform/:version', routes.update)
router.get('/update/:platform/:version/:targetFile', routes.update)
router.get('/update/win32/:version/RELEASES', routes.releases)

return (req, res) => {
Expand Down
4 changes: 2 additions & 2 deletions lib/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ module.exports = fileName => {

if (
(fileName.includes('mac') || fileName.includes('darwin')) &&
extension === 'zip'
(extension === 'yml')
) {
return 'darwin'
}

const directCache = ['exe', 'dmg', 'rpm', 'deb', 'AppImage']
const directCache = ['exe', 'dmg', 'rpm', 'deb', 'AppImage', 'zip']
return directCache.find(ext => ext === extension) || false
}
20 changes: 18 additions & 2 deletions lib/routes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Native
const urlHelpers = require('url');
const urlHelpers = require('url')

// Packages
const { send } = require('micro')
Expand Down Expand Up @@ -81,6 +81,10 @@ module.exports = ({ cache, config }) => {
platform = 'dmg'
}

if (platform === 'darwin') {
platform = 'dmg'
}

// Get the latest version from the cache
const latest = await loadCache()

Expand Down Expand Up @@ -110,7 +114,7 @@ module.exports = ({ cache, config }) => {
}

exports.update = async (req, res) => {
const { platform: platformName, version } = req.params
const { platform: platformName, version, targetFile } = req.params

if (!valid(version)) {
send(res, 500, {
Expand Down Expand Up @@ -142,6 +146,18 @@ module.exports = ({ cache, config }) => {
return
}

if (targetFile) {
if (shouldProxyPrivateDownload) {
for (const platform in latest.platforms) {
if (latest.platforms[platform].name === targetFile) {
proxyPrivateDownload(latest.platforms[platform], req, res)
break
}
}
return
}
}

// Previously, we were checking if the latest version is
// greater than the one on the client. However, we
// only need to compare if they're different (even if
Expand Down
2 changes: 1 addition & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const hazel = require('./index')
const hazel = require('.')

const {
INTERVAL: interval,
Expand Down
16 changes: 0 additions & 16 deletions now.json

This file was deleted.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,30 @@
},
"lint-staged": {
"*.js": [
"yarn test && :",
"yarn test --passWithNoTests && :",
"prettier --single-quote --no-semi --write --no-editorconfig",
"git add"
]
},
"dependencies": {
"@vercel/node": "^1.8.2",
"async-retry": "1.2.3",
"date-fns": "1.29.0",
"express-useragent": "1.0.12",
"fetch": "1.1.0",
"finalhandler": "1.1.0",
"handlebars": "4.0.11",
"install": "^0.13.0",
"jest": "24.0.0",
"micro": "9.3.3",
"ms": "2.1.1",
"node-fetch": "2.0.0",
"router": "1.3.2",
"semver": "5.5.0",
"stream-to-string": "1.1.0",
"test-listen": "1.1.0"
"test-listen": "1.1.0",
"vercel": "^20.1.0",
"yarn": "^1.22.10"
},
"devDependencies": {
"eslint-config-prettier": "2.9.0",
Expand Down
21 changes: 21 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": 2,
"env": {
"ACCOUNT": "Your GitHub Account",
"REPOSITORY": "Your GirHub Repository",
"TOKEN": "Your GitHub Token",
"URL": "http://localhost:3000"
},
"builds": [
{
"src": "lib/*.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": ".*",
"dest": "lib/server.js"
}
]
}

0 comments on commit b232ee3

Please sign in to comment.