forked from gruntjs/grunt-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
101 lines (87 loc) · 2.86 KB
/
Gruntfile.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
/*
* grunt-contrib
* http://gruntjs.com/
*
* Copyright (c) 2012 Tyler Kellen, contributors
* Licensed under the MIT license.
* https://github.com/gruntjs/grunt-contrib/blob/master/LICENSE-MIT
*/
'use strict';
module.exports = function(grunt) {
grunt.registerTask('build', function () {
var done = this.async();
var when = require('when');
var request = require('request');
var _ = require('lodash');
var deps = require('matchdep').filterPeer('grunt-contrib-*');
var baseurl = 'http://raw.github.com/gruntjs/'
// make http request for author file in a repo
var authorFile = function (dep) {
var deferred = when.defer();
var url = baseurl+dep+'/master/AUTHORS';
request.get({url: url}, function(err, res, body) {
if (res.statusCode != 200) {
grunt.fail.fatal('Failed to retrieve '+url);
} else {
deferred.resolve(body.split('\n'));
}
});
return deferred.promise
};
// make http request for package.json in a repo
var packageJSON = function (dep) {
var deferred = when.defer();
var url = baseurl+dep+'/master/package.json';
request.get({url: url, json: true}, function(err, res, body) {
if (res.statusCode != 200) {
grunt.fail.fatal('Failed to retrieve '+url);
} else {
deferred.resolve(body);
}
});
return deferred.promise
};
// write combined author file for all contrib repos
var writeAuthors = function (authors) {
var output =
'Tyler Kellen (http://goingslowly.com)\n' +
_.chain(authors)
.flatten()
.map(function(author) {
return author.trim();
})
.filter(function(author) {
return !(author.indexOf('Tyler Kellen') !== -1);
})
.sort()
.uniq(true, function(author) {
if (author.indexOf('(') !== -1) {
author = author.slice(0, author.indexOf('('));
}
return author;
})
.compact()
.value()
.join('\n');
grunt.file.write('AUTHORS', output);
};
// write combined readme for all contrib repos
var writeReadme = function (packages) {
var tmpl = grunt.file.read('docs/overview.tmpl');
var readme = grunt.template.process(tmpl, {data:{plugins:packages}});
grunt.file.write('docs/overview.md', readme);
};
// read all contrib author files
var authors = when.all(deps.map(authorFile));
// read all contrib package.json files
var packages = when.all(deps.map(packageJSON));
// write author/readme and flag completed
when.join(authors, packages).then(function (results) {
writeAuthors(results[0]);
writeReadme(results[1]);
done();
})
});
grunt.loadNpmTasks('grunt-contrib-internal');
grunt.registerTask('default', ['build', 'build-contrib']);
};