forked from skratchdot/elasticsearch-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
51 lines (47 loc) · 1.33 KB
/
gulpfile.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
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var async = require('async');
var fs = require('fs');
var exec = require('child_process').exec;
gulp.task('readme', function () {
var filename = './README.md';
fs.readFile(filename, 'utf-8', function (err, data) {
var sections = data.split('\n## Usage: ');
async.map(sections, function (section, callback) {
var tool, child;
// the first section is okay
if (section === sections[0]) {
callback(null, section);
} else {
section = section.split('### Examples');
tool = section[0].split('\n')[0];
child = exec('node ./lib/' + tool + ' --help', function (error, stdout, stderr) {
callback(error, [
tool,
'\n\n### Options\n\n```bash\n',
tool,
' --help\n\n',
stdout.toString().trim(),
'\n```\n\n### Examples',
section[1]
].join(''));
});
}
}, function (err, results) {
// results is now an array of stats for each file
var output = results.join('\n## Usage: ');
console.log(output);
fs.writeFile(filename, output, 'utf-8');
});
});
});
gulp.task('lint', function () {
return gulp.src('./lib/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('default', ['readme', 'lint']);
//handle errors
process.on('uncaughtException', function (e) {
console.error(e);
});