aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-09-30 23:58:01 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-10-01 12:17:30 -1000
commitab3a0ab5900e05e5c2227eca74196d9460a5354d (patch)
treea8f86c87cb885eb2dfa3e2600384e4680e484f16 /lib
parent3643ae071dc1e2ba89f67606bd267eb3e3f0f312 (diff)
downloadpatchfoo-ab3a0ab5900e05e5c2227eca74196d9460a5354d.tar.gz
patchfoo-ab3a0ab5900e05e5c2227eca74196d9460a5354d.zip
Render npm prebuilds
Diffstat (limited to 'lib')
-rw-r--r--lib/render-msg.js15
-rw-r--r--lib/render.js99
-rw-r--r--lib/serve.js54
3 files changed, 154 insertions, 14 deletions
diff --git a/lib/render-msg.js b/lib/render-msg.js
index 9b69603..186bb9f 100644
--- a/lib/render-msg.js
+++ b/lib/render-msg.js
@@ -255,6 +255,7 @@ RenderMsg.prototype.message = function (cb) {
case 'mutual/account': return this.mutualAccount(cb)
case 'npm-publish': return this.npmPublish(cb)
case 'npm-packages': return this.npmPackages(cb)
+ case 'npm-prebuilds': return this.npmPrebuilds(cb)
default: return this.object(cb)
}
}
@@ -540,7 +541,8 @@ RenderMsg.prototype.gitUpdate = function (cb) {
var done = multicb({pluck: 1, spread: true})
self.link(self.c.repo, done())
self.render.npmPackageMentions(self.c.mentions, done())
- done(function (err, a, pkgMentionsEl) {
+ self.render.npmPrebuildMentions(self.c.mentions, done())
+ done(function (err, a, pkgMentionsEl, prebuildMentionsEl) {
if (err) return cb(err)
self.wrap(h('div.ssb-git-update',
'git push ', a, ' ',
@@ -583,7 +585,8 @@ RenderMsg.prototype.gitUpdate = function (cb) {
'+ ' + self.c.commits_more + ' more commits') : '',
self.c.tags_more ? h('div',
'+ ' + self.c.tags_more + ' more tags') : '',
- pkgMentionsEl
+ pkgMentionsEl,
+ prebuildMentionsEl
), cb)
})
}
@@ -959,6 +962,14 @@ RenderMsg.prototype.npmPackages = function (cb) {
})
}
+RenderMsg.prototype.npmPrebuilds = function (cb) {
+ var self = this
+ self.render.npmPrebuildMentions(self.c.mentions, function (err, el) {
+ if (err) return cb(err)
+ self.wrap(el, cb)
+ })
+}
+
RenderMsg.prototype.npmPublishTitle = function (cb) {
var pkg = this.c.meta || {}
var name = pkg.name || pkg._id || '?'
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))
]))
})
}
diff --git a/lib/serve.js b/lib/serve.js
index 62e3629..6a08c4a 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -302,6 +302,7 @@ Serve.prototype.path = function (url) {
case '/git': return this.git(m[2])
case '/image': return this.image(m[2])
case '/npm': return this.npm(m[2])
+ case '/npm-prebuilds': return this.npmPrebuilds(m[2])
case '/npm-readme': return this.npmReadme(m[2])
}
return this.respond(404, 'Not found')
@@ -1971,6 +1972,59 @@ Serve.prototype.npm = function (url) {
)
}
+Serve.prototype.npmPrebuilds = function (url) {
+ var self = this
+ var parts = url.split('/')
+ var author = parts[1] && parts[1][0] === '@'
+ ? u.unescapeId(parts.splice(1, 1)[0]) : null
+ var name = parts[1]
+ var version = parts[2]
+ var prefix = 'prebuild:' +
+ (name ? name + '-' +
+ (version ? version + '-' : '') : '')
+
+ var render = self.app.render
+ var base = '/npm-prebuilds/' + (author ? u.escapeId(author) + '/' : '')
+ return pull(
+ ph('section', {}, [
+ ph('h3', [ph('a', {href: render.toUrl('/npm-prebuilds/')}, 'npm prebuilds'), ' : ',
+ name ? [ph('a', {href: render.toUrl(base + name)}, name), ' : '] : '',
+ version ? [ph('a', {href: render.toUrl(base + name + '/' + version)}, version)] : '',
+ ]),
+ ph('table', [
+ ph('thead', ph('tr', [
+ ph('th', 'publisher'),
+ ph('th', 'name'),
+ ph('th', 'version'),
+ ph('th', 'runtime'),
+ ph('th', 'abi'),
+ ph('th', 'platform+libc'),
+ ph('th', 'arch'),
+ ph('th', 'size'),
+ ph('th', 'tarball')
+ ])),
+ ph('tbody', pull(
+ self.app.blobMentions({
+ name: {$prefix: prefix},
+ author: author,
+ }),
+ paramap(function (link, cb) {
+ self.app.render.npmPrebuildMention(link, {
+ withAuthor: true,
+ author: author,
+ name: name,
+ version: version,
+ }, cb)
+ }, 4),
+ pull.map(u.toHTML)
+ ))
+ ])
+ ]),
+ self.wrapPage(prefix),
+ self.respondSink(200)
+ )
+}
+
Serve.prototype.npmReadme = function (url) {
var self = this
var id = decodeURIComponent(url.substr(1))