forked from gruntjs/gruntjs.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrunt-plugins.js
215 lines (192 loc) · 8.36 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/**
* 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 async = require('async');
var ent = require('ent');
var fs = require('fs');
require('date-utils');
// A list of grunt plugins that have wronged!
var bannedPlugins = [
'grunt-contrib-jst-2', // Reason: unofficial contrib plugin
'loadnpmtasks', // Reason: not a plugin
'dp-grunt-contrib-copy',
'grunt-contrib-yohtml', // Reason: unofficial contrib plugin
'grunt-contrib-quickstart', // Reason: unofficial contrib plugin
'grunt-contrib-coffeeify', // Reason: unofficial contrib plugin
'grunt-contrib-nodefy', // Reason: unofficial contrib plugin
'grunt-contrib-handlebars-rhengles', // Reason: unofficial contrib plugin
'grunt-contrib-juicepress', // Reason: unofficial contrib plugin
'grunt-contrib-build-crx', // Reason: unofficial contrib plugin
'grunt-test', // Reason: no real plugin
'grunt-testingoscar123', // Reason: no real plugin
'assemble-less-variables',
'grunt-contrib-eslint', // Reason: unofficial contrib plugin
'grunt-contrib-htmlone', // Reason: unofficial contrib plugin
'grunt-contrib-coffeeify', // Reason: unofficial contrib plugin
'grunt-contrib-compass-sourcemap', // Reason: unofficial contrib plugin
'grunt-contrib-spritify', // Reason: unofficial contrib plugin
'grunt-contrib-include', // Reason: unofficial contrib plugin
'grunt-contrib-juicepress', // Reason: unofficial contrib plugin
'grunt-contrib-hogan', // Reason: unofficial contrib plugin
'grunt-contrib-stylus2tss', // Reason: unofficial contrib plugin, no documentation
'grunt-contrib-smartdoc', // Reason: unofficial contrib plugin
'grunt-contrib-cjsc', // Reason: unofficial contrib plugin
'grunt-contrib-compressor', // Reason: unofficial contrib plugin
'grunt-contrib-license-report', // Reason: unofficial contrib plugin
'grunt-contrib-tishadow', // Reason: unofficial contrib plugin
'grunt-contrib-smartsprites', // Reason: unofficial contrib plugin, no documentation
'grunt-contrib-rubylint', // Reason: unofficial contrib plugin
'grunt-contrib-lualint', // Reason: unofficial contrib plugin
'grunt-contrib-levin-usemin', // Reason: unofficial contrib plugin
'grunt-contrib-quickstart', // Reason: unofficial contrib plugin
'grunt-contrib-i18next', // Reason: unofficial contrib plugin
'grunt-contrib-ftpush', // Reason: unofficial contrib plugin
'grunt-mindirect', // Reason: duplicate of contrib-uglify
'private-grunt-contrib-uglify', // Reason: duplicate of contrib-uglify
'grunt-handlebars-static', // Reason: duplicate of compile-handlebars
'grunt-contrib-jshint-reporter-tweaks', // Reason: unofficial contrib plugin
'grunt-sass-fork', // Reason: duplicate of grunt-contrib-sass
'grunt-gh-deploy', // Reason: duplicate of grunt-gh-pages
'grunt-github-pages', // Reason: duplicate of grunt-gh-pages
'grunt-contrib-cssmin-pre-2.1.0', // Reason: unofficial contrib plugin
'private-grunt-contrib-cssmin', // Reason: unofficial contrib plugin
'private-grunt-contrib-stylus', // Reason: unofficial contrib plugin
'grunt-contrib-zopfli', // Reason: unofficial contrib plugin, duplicate of grunt-zopfli
'grunt-htmlmin', // Reason: duplicate of contrib-htmlmin
'grunt-symbolic-link', // Reason: duplicate of contrib-symlink
'grunt-symlink', // Reason: duplicate of contrib-symlink
'grunt-symlinks', // Reason: duplicate of contrib-symlink
'grunt-coffee', // Reason: duplicate of contrib-coffee
'grunt-coffee-lint', // Reason: duplicate of grunt-coffeelint, missing documentation
'grunt-less', // Reason: duplicate of grunt-contrib-less
'grunt-scsslint', // Reason: duplicate of grunt-scss-lint
'grunt-css', // Reason: deprecated
'ngbp-contrib-lintcss', // Reason: missing documentation, duplicate of grunt-contrib-csslint
'ngbp-contrib-mincss', // Reason: missing documentation, duplicate of grunt-contrib-cssmin
'grunt-init-test', // Reason: missing documentation, does nothing
'grunt-contrib-githooks', // Reason: unofficial contrib plugin
'grunt-contrib-stylus-map', // Reason: unofficial contrib plugin
'grunt-contrib-dox', // Reason: unofficial contrib plugin
'grunt-contrib-requiregrep', // Reason: unofficial contrib plugin
'grunt-contrib-litchi', // Reason: unofficial contrib plugin
'grunt-contrib-remotecordova', // Reason: unofficial contrib plugin
'grunt-contrib-environment', // Reason: unofficial contrib plugin
'grunt-contrib-lessify', // Reason: unofficial contrib plugin
'grunt-contrib-appbuilder' // Reason: unofficial contrib plugin
];
var pluginFile = 'build/plugin-list.json';
function getPlugin(item, callback) {
var name = item.key[1];
var url = 'https://skimdb.npmjs.com/registry/' + name;
request({url: url, json: true}, function handlePlugin(error, response, body) {
if (!error && response.statusCode == 200) {
callback(null, condensePlugin(body));
} else {
console.log('Failed to get data for:', name);
callback(null, null);
}
});
}
function getDownloads(item, callback) {
var name = item.name;
var url = 'https://api.npmjs.org/downloads/point/last-month/' + name;
request({url: url, json: true}, function handlePlugin(error, response, body) {
if (!error && response.statusCode == 200) {
if (body.downloads) {
item.dl = body.downloads;
} else {
item.dl = 0;
}
callback(null, item);
} else {
callback(null, item);
}
});
}
function condensePlugin(plugin) {
var 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,
ds: plugin.description != null ? ent.encode(plugin.description) : '',
a: (plugin.author && plugin.author.name != null) ? plugin.author.name : '',
url: plugin.url,
v: gruntVersion,
// only get created and modified date, leave out all of the version timestamps
m: plugin.time.modified
//created: plugin.time.created
};
}
function getPlugins(opts, callback) {
console.log('Downloading plugin list, this will take 40 or more seconds...');
async.waterfall([
// download plugin names based on the keyword
function(callback) {
var keyword = 'gruntplugin';
var url = 'https://skimdb.npmjs.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) {
callback(null, body.rows);
} else {
callback(null, new Error(error));
}
});
},
function(results, callback){
console.log('Downloading npm data for each plugin...');
var filtered = _.filter(results, function (el) {
return _.indexOf(bannedPlugins, el.key[1]) == -1;
});
async.mapLimit(filtered, 200, getPlugin, function(err, results){
// registry can be out of sync with deleted plugins
var results = _.reject(results, function(plugin) { return plugin === null; });
callback(err, results);
});
},
function(results, callback){
console.log('Fetching download information...');
async.mapLimit(results, 200, getDownloads, function(err, results){
callback(err, results);
});
}
], function (err, pluginList) {
if (err) {
console.log(err);
} else {
//console.log('Downloading GitHub data for each plugin...');
console.log('Saving to file...');
var pluginData = JSON.stringify({ "aaData": pluginList });
fs.writeFile(pluginFile, pluginData, function (err) {
if (err) throw err;
console.log('Saved!');
if (callback) callback(err, true);
});
}
});
}
function download(opts, callback) {
opts = opts || {};
if (typeof opts === 'function') {
callback = opts;
opts = {};
}
fs.stat(pluginFile, function (err) {
if (err || !opts.cache) {
if (err) {
console.log('File missing...');
}
getPlugins(opts, callback);
} else {
console.log('File already cached. Manually delete to redownload...');
}
});
}
module.exports.download = download;