-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgrunt-plugins.js
65 lines (58 loc) · 2.12 KB
/
grunt-plugins.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* grunt-plugins.js - gets the plugin list from npm
* server.js serves the plugin list via the website.
*/
var request = require('request');
var _ = require('lodash');
var Q = require('q');
function condensePlugin(plugin) {
var keywords = keywords = _.last(_.values(plugin.versions)).keywords;
var gruntVersion,
latestTagInfo = plugin.versions[ plugin['dist-tags'].latest ];
if (latestTagInfo && latestTagInfo.peerDependencies && latestTagInfo.peerDependencies.grunt) {
gruntVersion = latestTagInfo.peerDependencies.grunt;
}
return {
name: plugin.name,
description: plugin.description,
author: plugin.author,
url: plugin.url,
github: plugin.repository != null ? plugin.repository.url : "",
keywords: keywords,
gruntVersion: gruntVersion,
// only get created and modified date, leave out all of the version timestamps
time: {modified: plugin.time.modified, created: plugin.time.created}
};
}
function fetchPluginList() {
return Q.fcall(function fetchPluginList() {
var deferred = Q.defer();
var keyword = 'gruntplugin';
var url = 'http://isaacs.iriscouch.com/registry/_design/app/_view/byKeyword?startkey=[%22' +
keyword + '%22]&endkey=[%22' + keyword + '%22,{}]&group_level=3';
request({url: url, json: true}, function handlePluginList(error, response, body) {
if(!error && response.statusCode == 200) {
deferred.resolve(body.rows);
} else {
deferred.reject(new Error(error));
}
});
return deferred.promise;
}).then(function getPlugin(list) {
var results = _.map(list, function(item) {
var deferred = Q.defer();
var name = item.key[1];
var url = 'http://isaacs.iriscouch.com/registry/' + name;
request({url: url, json: true}, function handlePlugin(error, response, body) {
if(!error && response.statusCode == 200) {
deferred.resolve(condensePlugin(body));
} else {
deferred.reject(new Error(error));
}
});
return deferred.promise;
});
return Q.all(results);
});
}
exports.fetchPluginList = fetchPluginList;