diff --git a/lib/aliases.js b/lib/aliases.js index 915bbb8..8d65c43 100644 --- a/lib/aliases.js +++ b/lib/aliases.js @@ -3,11 +3,12 @@ const aliases = { exe: ['win32', 'windows', 'win'], deb: ['debian'], rpm: ['fedora'], - AppImage: ['appimage'] + AppImage: ['appimage'], + dmg: ['dmg'] } module.exports = platform => { - if(typeof aliases[platform] !== 'undefined') { + if (typeof aliases[platform] !== 'undefined') { return platform } diff --git a/lib/cache.js b/lib/cache.js index f0c30c2..65c5c68 100644 --- a/lib/cache.js +++ b/lib/cache.js @@ -19,13 +19,15 @@ module.exports = class Cache { } if (token && !url) { - const error = new Error('Neither NOW_URL, nor URL are defined, which are mandatory for private repo mode') + const error = new Error( + 'Neither NOW_URL, nor URL are defined, which are mandatory for private repo mode' + ) error.code = 'missing_configuration_properties' throw error } this.latest = {} - this.lastUpdate = null; + this.lastUpdate = null this.cacheReleaseList = this.cacheReleaseList.bind(this) this.refreshCache = this.refreshCache.bind(this) @@ -41,17 +43,20 @@ module.exports = class Cache { headers.Authorization = `token ${token}` } - const { status, body } = await retry(async () => { - const response = await fetch(url, { headers }) + const { status, body } = await retry( + async () => { + const response = await fetch(url, { headers }) - if (response.status !== 200) { - throw new Error( - `Tried to cache RELEASES, but failed fetching ${url}, status ${status}` - ) - } + if (response.status !== 200) { + throw new Error( + `Tried to cache RELEASES, but failed fetching ${url}, status ${status}` + ) + } - return response; - }, { retries: 3 }); + return response + }, + { retries: 3 } + ) const content = await convertStream(body) const matches = content.match(/[^ ]*\.nupkg/gim) @@ -76,17 +81,20 @@ module.exports = class Cache { headers.Authorization = `token ${token}` } - const response = await retry(async () => { - const response = await fetch(url, { headers }) + const response = await retry( + async () => { + const response = await fetch(url, { headers }) - if (response.status !== 200) { - throw new Error( - `GitHub API responded with ${response.status} for url ${url}` - ) - } + if (response.status !== 200) { + throw new Error( + `GitHub API responded with ${response.status} for url ${url}` + ) + } - return response; - }, { retries: 3 }); + return response + }, + { retries: 3 } + ) const data = await response.json() @@ -160,7 +168,7 @@ module.exports = class Cache { const { lastUpdate, config } = this const { interval = 15 } = config - if (lastUpdate && (Date.now() - lastUpdate) > ms(`${interval}m`)) { + if (lastUpdate && Date.now() - lastUpdate > ms(`${interval}m`)) { return true } @@ -177,6 +185,6 @@ module.exports = class Cache { await refreshCache() } - return latest + return Object.assign({}, latest) } } diff --git a/lib/platform.js b/lib/platform.js index f0f024c..764d38f 100644 --- a/lib/platform.js +++ b/lib/platform.js @@ -2,18 +2,15 @@ const { extname } = require('path') module.exports = fileName => { - const extension = extname(fileName).split('.')[1] + const extension = extname(fileName).slice(1) - if ((fileName.includes('mac') || fileName.includes('darwin')) && extension === 'zip') { + if ( + (fileName.includes('mac') || fileName.includes('darwin')) && + extension === 'zip' + ) { return 'darwin' } - const directCache = ['exe', 'rpm', 'deb', 'AppImage'] - const index = directCache.indexOf(extension) - - if (index > -1) { - return directCache[index] - } - - return false + const directCache = ['exe', 'dmg', 'rpm', 'deb', 'AppImage'] + return directCache.find(ext => ext === extension) || false } diff --git a/lib/routes.js b/lib/routes.js index dbf94cf..84744f2 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -180,6 +180,14 @@ module.exports = ({ cache, config }) => { exports.overview = async (req, res) => { const latest = await loadCache() + // Filter out special platforms that should not + // be shown on the overview page + Object.keys(latest.platforms).forEach(platform => { + if (platform === 'dmg') { + delete latest.platforms[platform] + } + }) + try { const render = await prepareView() diff --git a/package.json b/package.json index ba6ce3a..2675f30 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,8 @@ }, "lint-staged": { "*.js": [ - "yarn test", - "prettier --single-quote --no-semi --write", + "yarn test && :", + "prettier --single-quote --no-semi --write --no-editorconfig", "git add" ] }, diff --git a/test/platform.test.js b/test/platform.test.js index e781937..ef4b452 100644 --- a/test/platform.test.js +++ b/test/platform.test.js @@ -12,6 +12,11 @@ describe('Platform', () => { expect(result).toBe('deb') }) + it('Should parse dmg', () => { + const result = platform('hyper-2.1.1.dmg') + expect(result).toBe('dmg') + }) + it('Should return false for unknown files', () => { const result = platform('hi.txt') expect(result).toBe(false)