Skip to content

Instantly share code, notes, and snippets.

@indexzero
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indexzero/262e8282e8b1a485d285 to your computer and use it in GitHub Desktop.
Save indexzero/262e8282e8b1a485d285 to your computer and use it in GitHub Desktop.
A CouchDB view for checking which modules use the existing github "user/repo" syntax

A CouchDB view for checking which modules use the existing github "user/repo" syntax

Usage

  1. Copy / paste design-doc.json into a new document in your registry
  2. Visit http://localhost:5984/registry/_design/synxtax/_view/git?startkey=["latest"]
  3. Output on May 9th, 2014
{"rows":[
{"key":null,"value":225}
]}
{
"_id": "_design/syntax",
"_rev": "10-8d55a9aa58a4d275cac9e6a76a0e8b66",
"language": "javascript",
"views": {
"git": {
"map": "function (doc) {\n if (doc._id.match(/^npm-test-.+$/) &&\n doc.maintainers &&\n doc.maintainers[0].name === 'isaacs') {\n return;\n }\n\n var re = /^([\\w+\\-]+)\\/([\\w+\\-]+)/;\n\n //\n // Check the dependencies of a single version\n //\n function checkDeps(ver, num) {\n num = num || ver.version;\n var match;\n for (var dep in ver.dependencies) {\n match = false;\n if ((match = re.exec(ver.dependencies[dep]))) {\n emit([num, doc._id, dep, ver.dependencies[dep]], 1);\n }\n }\n }\n\n if (!doc.versions) {\n return;\n }\n \n var latest = doc['dist-tags'] && doc['dist-tags'].latest\n if (latest) {\n latest = doc.versions && doc.versions[latest];\n if (latest) {\n checkDeps(latest, 'latest');\n }\n }\n \n for (var v in doc.versions) {\n checkDeps(doc.versions[v]);\n }\n}",
"reduce": "_sum"
}
}
}
function (doc) {
if (doc._id.match(/^npm-test-.+$/) &&
doc.maintainers &&
doc.maintainers[0].name === 'isaacs') {
return;
}
var re = /^([\w+\-]+)\/([\w+\-]+)/;
//
// Check the dependencies of a single version
//
function checkDeps(ver, num) {
num = num || ver.version;
var match;
for (var dep in ver.dependencies) {
match = false;
if ((match = re.exec(ver.dependencies[dep]))) {
emit([num, doc._id, dep, ver.dependencies[dep]], 1);
}
}
}
if (!doc.versions) {
return;
}
var latest = doc['dist-tags'] && doc['dist-tags'].latest
if (latest) {
latest = doc.versions && doc.versions[latest];
if (latest) {
checkDeps(doc.versions[latest], 'latest');
}
}
for (var v in doc.versions) {
checkDeps(doc.versions[v]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment