From ab3a0ab5900e05e5c2227eca74196d9460a5354d Mon Sep 17 00:00:00 2001 From: cel Date: Sat, 30 Sep 2017 23:58:01 -1000 Subject: Render npm prebuilds --- lib/render.js | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 87 insertions(+), 12 deletions(-) (limited to 'lib/render.js') diff --git a/lib/render.js b/lib/render.js index cc08259..a7d02be 100644 --- a/lib/render.js +++ b/lib/render.js @@ -410,12 +410,39 @@ Render.prototype.npmPackageMentions = function (links, cb) { done(function (err, mentionEls) { cb(null, h('table', h('thead', h('tr', - h('td', 'package'), - h('td', 'version'), - h('td', 'tag'), - h('td', 'size'), - h('td', 'tarball'), - h('td', 'readme') + h('th', 'package'), + h('th', 'version'), + h('th', 'tag'), + h('th', 'size'), + h('th', 'tarball'), + h('th', 'readme') + )), + h('tbody', mentionEls) + )) + }) +} + +Render.prototype.npmPrebuildMentions = function (links, cb) { + var self = this + var prebuildLinks = u.toArray(links).filter(function (link) { + return /^prebuild:/.test(link.name) + }) + if (prebuildLinks.length === 0) return cb(null, '') + var done = multicb({pluck: 1}) + prebuildLinks.forEach(function (link) { + self.npmPrebuildMention(link, {}, done()) + }) + done(function (err, mentionEls) { + cb(null, h('table', + h('thead', h('tr', + h('th', 'name'), + h('th', 'version'), + h('th', 'runtime'), + h('th', 'abi'), + h('th', 'platform+libc'), + h('th', 'arch'), + h('th', 'size'), + h('th', 'tarball') )), h('tbody', mentionEls) )) @@ -423,6 +450,7 @@ Render.prototype.npmPackageMentions = function (links, cb) { } Render.prototype.npmPackageMention = function (link, opts, cb) { + var nameRegex = /'prebuild:{name}-v{version}-{runtime}-v{abi}-{platform}{libc}-{arch}.tar.gz'/ var parts = String(link.name).replace(/\.tgz$/, '').split(':') var name = parts[1] var version = parts[2] @@ -470,12 +498,59 @@ Render.prototype.npmPackageMention = function (link, opts, cb) { href: self.toUrl('/npm-readme/' + encodeURIComponent(link.link)), title: 'package contents' }, 'readme') - : h('form', {action: '', method: 'post'}, - h('input', {type: 'hidden', name: 'action', value: 'want-blobs'}), - h('input', {type: 'hidden', name: 'async_want', value: '1'}), - h('input', {type: 'hidden', name: 'blob_ids', value: link.link}), - h('input', {type: 'submit', value: 'fetch'}) - )) + : self.blobFetchForm(link.link)) + ])) + }) +} + +Render.prototype.blobFetchForm = function (id) { + return h('form', {action: '', method: 'post'}, + h('input', {type: 'hidden', name: 'action', value: 'want-blobs'}), + h('input', {type: 'hidden', name: 'async_want', value: '1'}), + h('input', {type: 'hidden', name: 'blob_ids', value: id}), + h('input', {type: 'submit', value: 'fetch'}) + ) +} + +Render.prototype.npmPrebuildNameRegex = /^prebuild:(.*?)-v([0-9]+\.[0-9]+.*?)-(.*?)-v(.*?)-(.*?)-(.*?)\.tar\.gz$/ + +Render.prototype.npmPrebuildMention = function (link, opts, cb) { + var m = this.npmPrebuildNameRegex.exec(link.name) + if (!m) return cb(null, '') + var name = m[1], version = m[2], runtime = m[3], + abi = m[4], platformlibc = m[5], arch = m[6] + var self = this + var done = multicb({pluck: 1, spread: true}) + var base = '/npm-prebuilds/' + (opts.author ? u.escapeId(link.author) + '/' : '') + self.app.getAbout(link.author, done()) + self.app.getBlobState(link.link, done()) + done(function (err, about, blobState) { + if (err) return cb(err) + cb(null, h('tr', [ + opts.withAuthor ? h('td', h('a', { + href: self.toUrl(link.author) + }, about.name), ' ') : '', + h('td', h('a', { + href: self.toUrl(base + name) + }, name), ' '), + h('td', h('a', { + href: self.toUrl('/npm/' + name + '/' + version) + }, version), ' '), + h('td', runtime, ' '), + h('td', abi, ' '), + h('td', platformlibc, ' '), + h('td', arch, ' '), + h('td', {align: 'right'}, link.size != null ? [ + self.formatSize(link.size), ' ' + ] : ''), + h('td', typeof link.link === 'string' ? h('code', h('a', { + href: self.toUrl('/links/' + link.link) + }, link.link.substr(0, 8) + '…')) : ''), + h('td', + blobState === 'wanted' ? + 'fetching...' + : blobState ? '' + : self.blobFetchForm(link.link)) ])) }) } -- cgit v1.2.3